You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, wonderful library; thanks for your work on it.
If I have a component with a useEffect hook with an empty dependency array I would expect the callback function to be called once. However if the callback function calls a state updating function (i.e. one returned by useState or the dispatch function returned by useReducer) the callback is called twice. Here is an example:
This is the simplest example I could make to reproduce the problem. The context for this is I wanted to use useEffect to have a component make an HTTP request once on mount and store the results in state, but I kept seeing two HTTP requests being made.
The text was updated successfully, but these errors were encountered:
Hello @paaatrick. Sorry for the late response but I did not find much time to investigate this issue. Would you be willing to try and peak under the hood to find what could cause this?
First, wonderful library; thanks for your work on it.
If I have a component with a
useEffect
hook with an empty dependency array I would expect the callback function to be called once. However if the callback function calls a state updating function (i.e. one returned byuseState
or thedispatch
function returned byuseReducer
) the callback is called twice. Here is an example:I would expect the
Test
component to render1
, but instead it renders2
. The equivalent example using thereact-dom
renderer results in 1 being displayed (https://codesandbox.io/s/brave-grass-wik3s?file=/src/App.js).This is the simplest example I could make to reproduce the problem. The context for this is I wanted to use
useEffect
to have a component make an HTTP request once on mount and store the results in state, but I kept seeing two HTTP requests being made.The text was updated successfully, but these errors were encountered: