doSomething((myElement, [myState, setMyState]) => {
const mouseOverHandler = e => {
setMyState(/* some always changing value */)
}
myElement.addEventListener('mouseover', mouseOverHandler)
return () => {
myElement.removeEventListener('mouseover', mouseOverHandler)
}
}, [myElement, myState])
is constantly being re-called, even though it does not have to be. Requiring the state in the statesAndRefs array (to use the setState function) does not imply the usage of the state's value.
Providing the option to use a setState without listening to state changes will drastically improve performance.
A state listener like this
is constantly being re-called, even though it does not have to be. Requiring the state in the
statesAndRefs
array (to use thesetState
function) does not imply the usage of the state's value. Providing the option to use asetState
without listening to state changes will drastically improve performance.