简体   繁体   English

我可以分发使用redux的React组件吗?

[英]can I distribute a react component that uses redux?

I've got a big component that I am making that will take one large standardized object and display it. 我正在制作一个很大的组件,它将带一个大的标准化对象并显示它。 I will have many child components within the main distributed component and I don't want to have to make it ugly by typing in props all the way down the chain... 我将在主要的分布式组件中有许多子组件,并且我不想在整个链下一直输入道具而使其变得丑陋。

const User = ({ user }) => {
  return (
    <BasicInfo
      name={user.basic.name}
      tagline={user.basic.tagline}
      email={user.basic.email}
      ...more props
    >
    <OtherInfo
      infoprops={info}
      ...long list of props
    >
  )
}

It would end up being a very long list of props that might go 3 or 4 levels deep and I really don't want to have to keep track of what is passing what on manually... 最终将是一堆很长的道具,可能会深入3或4个级别,我真的不想跟踪手动传递的内容...

I got used to using redux, so I could do something like connect() but can I use redux here with a distributed component? 我已经习惯了使用redux,所以我可以做类似connect()事情,但是我可以在这里使用Redux和分布式组件吗? would the state of my one component be kept separate from the end users redux (if they are even using redux)? 我的一个组件的状态是否与最终用户redux分开(如果他们甚至使用redux)?

Is this even wise? 这是否明智? Maybe there is aa better way than using redux? 也许有比使用redux更好的方法? Thanks 谢谢

I don't think its a good idea to use redux to make your component reusable since redux is based on a single store for a whole application so, if you create a store, the app would not be able to create its own. 我认为使用redux来使组件可重用不是一个好主意,因为redux基于整个应用程序的单个存储,因此,如果创建存储,则该应用程序将无法创建自己的存储。

Given that, I do think you could create your custom store using the Singleton pattern (as you usually would do with android) without forcing your possible users to add redux to their project just to use your component. 鉴于此,我确实认为您可以使用Singleton模式创建自定义商店(就像您通常使用android一样),而不必强迫可能的用户仅在使用组件的情况下将redux添加到他们的项目中。

I can't guide you more without knowing your component hierarchy or behaviour. 在不了解您的组件层次结构或行为的情况下,我无法为您提供更多指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将操作信息传递给组件、React + Redux? - How can i pass Actions info to Component, React + Redux? 如何在创建时为 React 组件初始化 Redux state? - How can I initialize Redux state for React component on its creation? 如何根据Redux操作结果更新React组件 - How can I update a React component depending on redux action outcome 使用React组件分发CSS - Distribute CSS with a React component React-redux:当它在功能组件中工作时,为什么我不能访问类组件中的状态属性? - React-redux: Why can't I access state properties in a class component, when it works in a functional component? React Redux 如何正确分配组件 - React Redux how to properly distribute components 如何在使用Flow时将道具传播到使用精确道具的React组件? - How can I spread props to a React component that uses exact props when using Flow? 如何在没有组件闪烁的情况下根据来自我的 API 的数据重新路由 - React/Redux - How can I reroute based on data from my API without component flashing - React/Redux React / Redux:如何将此状态从一个组件传递到另一个文件? - React/Redux: How can I pass this state from one component to another file? 如何与其他组件共享 react-redux 连接组件中的功能? - How can I share a function in a react-redux connected component with other components?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM