简体   繁体   English

如何使用 Action/Flux [JS/REACT] 处理 onClick

[英]How can I handle a onClick using Action/Flux [JS/REACT]

I am using Flux to manage the data architecture of my React App .我正在使用 Flux 来管理我的 React App 的数据架构 I understand the entire process when I am using actions to manage fetch calls to mockup API or real API and how to use dispatcher, stores etc... But what happens when I have something simple like a button that just hide a modal .当我使用操作来管理对模型 API 或真正的 API 的提取调用以及如何使用调度程序、存储等,我了解整个过程... In this case do I need to involve an action in the process or just I can do something like this:在这种情况下,我是否需要在过程中涉及一个动作,或者我可以做这样的事情:

onClick={handleInputChange}

and then manage the setStare inside the function.然后管理function里面的setStare。 Is this a good practice or not?.这是一个好习惯吗? If not any tip about how to create a action to manage this.如果没有关于如何创建操作来管理它的任何提示。

Thank you very much for your time非常感谢您的宝贵时间

If the state of modal is private to the component and not needed anywhere else in the application, than it's a good practice to have it inside the local state of functional component using useState hook.如果 modal 的 state 是组件私有的,并且在应用程序的其他任何地方都不需要,那么最好使用 useState 钩子将它放在功能组件的本地 state 中。

You should not dispatch action for such thing and also no need to keep it in global store.您不应该为此类事情发送操作,也无需将其保存在全局存储中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM