I am just going through a confusion so far. I am developing a React application for that some amount of API call is required. so I just confused with whether calling the API in the component and passing the dats by props to the required components or Using redux thunk to fetch the api's and store in to a React store and fetching the required data by dispatching the action when ever it required.
Suggestions will be appreciable :)
Calling the API is surely gonna be done in the component. Like so:
const Component = () => {
useEffect(() => {
const fn = async () => {
await apiCall()
}
fn()
}, [])
}
But your question resides on where you should store it.
This is simple:
redux-persist
(https://github.com/rt2zz/redux-persist) so it's not only to have a global object you can access.Features:
a. Persistance b. Global state accesible anywere c. Enhanced debugging with Redux dev tools
prop drilling
then React.Context
is a good optiondrilling
2 or 3 leves with your props, just don't overkill it using a Context