npm i mainam-react-utils
in root component import this library
import stateUtils from 'mainam-react-utils';
stateUtils.init(React);
and then, in function component you can init state with below example:
import {createState} from 'react'
const refState = createState({
count2: 0,
count: 0
})
#support callback
refState.setState({
count: refState.state.count+1
}, newState=>{ console.log(newState) });
#support promise
let newState = await refState.setState({
count: refState.state.count+1
});
console.log(newState)