Search code examples
javascriptreactjsactionflux

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


I am using Flux to manage the data architecture of my 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. 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. 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


Solution

  • 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.

    You should not dispatch action for such thing and also no need to keep it in global store.