React Hook “useEffect” is called conditionally

后端 未结 4 2214
再見小時候
再見小時候 2020-12-15 04:53

React is complaining about code below, saying it useEffect is being called conditionally:

4条回答
  •  遥遥无期
    2020-12-15 05:19

    The issue here is that when we are returning null from the if block, the useEffect hook code will be unreachable, since we returned before it, and hence the error that it is being called conditionally.

    You might want to define all the hooks first and then start writing the logic for rendering, be it null or empty string, or a valid JSX.

提交回复
热议问题