user13647380
user13647380

Reputation: 93

Is it best practice to keep form state in redux store?

I was learning react and redux and wanted to create form having several fields. So, since the form data is required for other components to work properly, I thought of keeping form state in redux store. But, what I assume is that since every time a user clicks a button in keyboard, new action is dispatched to store. The question is will it affect performance of my app? Again, is it ok to keep form state in redux store and when every time we click a button in keyboard, new action is dispatched to store? Wont't it hit performance?

Upvotes: 2

Views: 2045

Answers (2)

Engincan Veske
Engincan Veske

Reputation: 1585

Actually, when you use the redux store, you do not have to dispatch event in every DOM activity. For instance, let assume user in /home route, when the user redirects to /list route you call the useEffect() lifecycle method for dispatching an action. And this action brings a list from the database. But when the all list items listed, and want to select one of them for display it's a detail page, you don't have to dispatch an action again. You can pass the props to another component (like "DetailComponent"). And in that component, you can show the information without dispatch an action.

Upvotes: 0

markerikson
markerikson

Reputation: 67459

We specifically recommend that most form state probably shouldn't be kept in Redux. However, it's your app, so you should evaluate the specific use cases you need to deal with to determine the right approach.

Upvotes: 4

Related Questions