26
loading...
This website collects cookies to deliver better user experience
const [state, setState] = useState();
setState
function returned by React.useState
is fixed, and there is no need to consider weird problems when using it, and there is no need to put setState
in the dependencies of other Hooks.setState
, the reference will not change, just feel free to use it.const [state, setState] = useState();
useInterval(() => {
console.log(state);
}, 1000);
useInterval
at any time is always the latest, that is, the state
is always the latest.$ npm install --save ahooks@next
# or
$ yarn add ahooks@next