I'm testing the new React Hooks, and I've encountered a behavior I cannot fix (and comprehend neither). Basically, I have my functional component and inside it a function in which i set the hook. This function is passed to a Component rendered, and it's called from this last rendered Component using the props. Too bad that the hooks of the parent does not update accordingly!
I know it may seems difficult to understand, but I've reproduced the error here https://codesandbox.io/s/vvwp33l7o5
As you can see, in App
Component I've the onResize
function that should update the counter
hook. This function is passed to the ResizeObserverContainerHook
Component, and from this latter is called when ResizeObseverContainerHook
div is resized. As you can see, the width
and the height
variables in onResize
function are correct, but the counter
hook seems not to update! In fact, it stays equal to 1
forever.
I don't know, it seemes that I cannot update the hook from outside the Component ( and that's like the state in React Stateful Component, but at least I could passing a function like in this case, but it doesn't work :/ ).
Any idea how I can make that setCounter
at like 12 of index.js
works?