I was searching around the web, but I couldn't find a complete answer.
Let's imagine the following scenario:
I have to fetch a collection of data from an endpoint and display it in one single component ("page") in React. There is NO other component in the app that displays this data.
Plus every time the user enters the rout we have to fetch the data again.
In the above scenario does it make sense to store data in Redux? If yes, are there any advantages?
Personally I would inject the service that provides the data via props, call the service on mounted effect and store data in the React state of the component, because I really don't needed it anywhere else in the app.
CodePudding user response:
You are absolutely right there is no need to use redux
if you are fetching and using data in the same component and not anywhere else.
I would only recommend using redux
or any state management tool
if you want to share the data to multiple components and want to avoid prop drilling
.
Even if you are sharing data with one or two components I would still suggest using hooks
instead of redux
.
CodePudding user response:
No need of Redux
for state management in the above scenario. We use Redux
to manage states across different component or application level. Otherwise we can use props,hooks for the state management.