如何在维护不同的 Mobx 存储的同时使用相同的组件?
我有一个名为 keypair.js 的组件,
- 单击“添加”按钮后,它会创建三个文本框和一个删除按钮。
- 单击删除按钮后,它会删除该行。
这就像邮递员实现一样,因此该密钥对将用作标头组件和参数组件。
现在,当我将其用作可重用组件时,我在 Header 组件中所做的任何更改也会反映在 Parameter 组件中。
我也尝试导出商店类并在单个组件上创建实例,但这也不起作用。检查我之前的实现,下面的实现可以工作,但状态在两个组件之间共享。
I have a component called keypair.js
- On clicking add button, it creates three text boxes and one delete button.
- on clicking delete button, it deletes that row.
This is like postman implementation, so this keypair will be used as Header component as well as Parameter component.
Now, when I am using this as a reusable component, whatever changes I am making at Header component it is also reflected at Parameter component.
I have tried to export the store class as well and creating instance on the individual component but that also doesn't work. Check my previous implementation below which work but state is shared between the two components.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在有了答案。为了维护不同的存储实例,只需从存储本身导出 2 个或更多实例即可。我不知道为什么导出商店类并在组件中创建实例不起作用。
I have the answer for it now. For maintaining different instances of store simply export 2 or more instances from the store itself. I don't know why exporting the store class and creating instance in the component doesn't work.