motivation
upgrade react useState hook, let the state been initialized only one time
useState
traditional ; { // if user pass a heavy state to useState // this state will been initialized in every render period const heavyState = ; return <h3>heavyStatelength</h3>;}
useStateOnce
with useStateOnce
accept normal state or function state
if user pass function state to useStateOnce
, it will only been called one time
so user can completely replace React.useState
with useStateOnce
;; const state = { console; return Array1000000;}; { // useStateOnce accept normal state or function state; // if user pass function state to useStateOnce, it will only been called one time const heavyState setHeavyState = ; return <h3>heavyStatelength</h3>;}