Is it common to fetch data from the backend for every React view that needs access to data, or is there a different, efficient way to do this? | Hashnode
Is it common to fetch data from the backend for every React view that needs access to data, or is there a different, efficient way to do this?
Fetching data for every react view “seems” a little inefficient, putting it inside the lifecycle hook: componentDidMount. Is it a common practice? How do you handle data fetches in your React apps?
Correct me if I am wrong but isn't this what Redux is for? I would assume you would create all your views and have them tied to a piece of state.
I would also assume you could have the state initialized with the data from the backend so that your views don't have a promise call. And have lets say a save button or something be the even that triggers an save to the back end directly while also updating the state.
But I am very new to React but come from Angular and that's how I keep from ever having to to call to the back end from my view. Is there not a way to preload a routes state with content before the page even loads?
Marcus
Full Stack Developer
Correct me if I am wrong but isn't this what Redux is for? I would assume you would create all your views and have them tied to a piece of state.
I would also assume you could have the state initialized with the data from the backend so that your views don't have a promise call. And have lets say a save button or something be the even that triggers an save to the back end directly while also updating the state.
But I am very new to React but come from Angular and that's how I keep from ever having to to call to the back end from my view. Is there not a way to preload a routes state with content before the page even loads?