P粉6857572392023-08-11 12:31:09
In your useEffect
, you are not calling fetchImage
, you are returning it.
Will
useEffect(()=>fetchImage, [])
change into
useEffect(()=>fetchImage(), [])
or directly
useEffect(fetchImage, [])
The reason why it can run in the local environment is a bit interesting. When you return a function in a useEffect
hook function, it will be used during the component's destruction phase, which means that the function will be called when React unloads the component. In development mode, React will unmount and remount the component after mounting it, thus calling fetchImage
- your destruction function. This doesn't happen in a build environment.