We’ll fire up json-server so we can run our application against a server. We’ll take advantage of the fetch polyfill provided by create-react-app and leverage the componentDidMount lifecycle event to load our initial todo list. We’ll also add an error message to our UI in the case that the server is unavailable.
When I ran yarn test
, I got TypeError: Network request failed
.
I searched stackoverflow and solved the problem by using:
import fetch from 'isomorphic-fetch'
Unfortunately, this lesson left out a fairly important/tricky part of fetching state, which is what to do when a component unmounts while the data is being fetched. React will currently throw a console warning if you don't intentionally handle this situation. Since this is a "Production Quality" app tutorial, seems like an important thing to address.
Absolutely agree with Chris! I hoped this would be covered. Without clearing unresolved promises before unmount the code is definitely not production ready in my opinion.
what a shame :(