[英]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.