I had recently implemented something similar to this.
const[loading,setLoading]=useState(false)
I did the same thing, initializing loading state to false. However, my coworkers argued that it could be
const[loading,setLoading]=useState(true)
because the Hook will eventually set loading state to true any way. I argued that the Hook isn't actually fetching until the effect runs, which is why I initialized loading state to false. I eventually gave in and initialized loading state to true because I felt like we were bikeshedding.
Eventually found one good thing about initializing loading state to true. If the component using this custom fetch Hook rendered some other content, it won't flicker. In your case, this shouldn't happen though since BookList isn't rendering anything other than the fetched books.
I had recently implemented something similar to this.
I did the same thing, initializing
loading
state tofalse
. However, my coworkers argued that it could bebecause the Hook will eventually set
loading
state totrue
any way. I argued that the Hook isn't actually fetching until the effect runs, which is why I initializedloading
state tofalse
. I eventually gave in and initializedloading
state totrue
because I felt like we were bikeshedding.Anyway, what do you think?
Eventually found one good thing about initializing
loading
state totrue
. If the component using this custom fetch Hook rendered some other content, it won't flicker. In your case, this shouldn't happen though since BookList isn't rendering anything other than the fetched books.That's true! I'll update the post and add your note to it.