drinking-code / cherry-soda

Just another (super cool) JavaScript web framework.
7 stars 0 forks source link

Design deficiency with rapidly changing states #5

Open drinking-code opened 1 year ago

drinking-code commented 1 year ago

A state listener like this

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.