react-data-fetching icon indicating copy to clipboard operation
react-data-fetching copied to clipboard

Initial isLoading should be set to true

Open djm158 opened this issue 8 years ago • 0 comments

To my understanding, on first render, componentDidMount() is not called and isLoading is false even though data has not been loaded yet. This could leave you with undefined state on initial render. For example, I make an API call that returns an array, and set a variable const returnedData = data in my App component. My data will not be loaded yet, so the client will not render a loading message and also throw an error at returnedData.map(...) because it will think returnedData is a valid object.

The solution would be setting isLoading = true in the constructor, which will properly display a loading message until data is loaded.

p.s. Thank you for making these awesome tutorials! I found this and your post on higher order components really beneficial .

djm158 avatar Nov 09 '17 20:11 djm158