Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I absolutely avoid using useState with redux?

Okay I am using redux for state management in my react app. Now the question I have is, would it be all right to use useState knowing that I would only be using that state in one component only( i.e. the component that it was created in). It doesn't need to be passed, to other components(not even its children). So can I use useState in between of redux? I need to use redux btw.

like image 445
Ioe Materials Avatar asked May 18 '21 01:05

Ioe Materials


People also ask

Should I put all state in Redux?

Some users prefer to keep every single piece of data in Redux, to maintain a fully serializable and controlled version of their application at all times. Others prefer to keep non-critical or UI state, such as “is this dropdown currently open”, inside a component's internal state. Using local component state is fine.

Should I use Redux with Hooks?

Redux and React Hooks should be seen as complements and also as different things. While with the new React Hooks additions, useContext and useReducer, you can manage the global state, in projects with larger complexity you can rely on Redux to help you manage the application data.

Should you always use Redux with React?

Using Redux also means learning how it works, which again could be a waste of time if you don't need it. As a rule of thumb - and one shared by one of Redux's creators, Dan Abramov - you don't need to use Redux unless you're unable to manage state within React or other front-end frameworks you're working with.

Should I use Redux or react State for my App?

Another consideration is how many components in your React app need to access the state. The more state needs to be shared between different components in your app, the more benefit there is to using the Redux store. If the state feels isolated to a specific component or a small part of your app, React state may be a better option.

Should I use Redux for state sharing?

Sometimes, old-fashioned state sharing between different components works as well and improves the maintainability of your code. Also, you can avoid using Redux if your data comes from a single data source per view.

Which applications don’t need Redux?

Applications that consist of mostly simple UI changes most often don’t require a complicated pattern like Redux. Sometimes, old-fashioned state sharing between different components works as well and improves the maintainability of your code.

What are the downsides of Redux?

You’ll likely experience data inconsistency bugs, a fearsome nightmare for frontend developers. As shown in the image, Redux takes away the responsibility from individual components to manage a state. Instead, we create a single store that handles our state management.


2 Answers

You should use local state i.e. useState as much as possible. Redux state should be the last resort. Only use Redux state if you absolutely need to pass data from one end of the application all the way to another end. This is both good practice for tight coupling and good performance.

like image 87
Matthew Kwong Avatar answered Nov 01 '22 03:11

Matthew Kwong


Yes, for sure. There's no reason to use your Redux state for local state.

like image 43
Aadmaa Avatar answered Nov 01 '22 03:11

Aadmaa