Posts > create your own useState
April 7, 2023
Creating a useState
method using vanilla javascript.
function stringState(initial) {
let initialState = initial;
let newValue;
return [
() => initialState,
function newValue(v){
initialState = v;
}
]
}
const [strGetter, strSetter] = stringState('boop');
console.log(strGetter());
strSetter('beep');
console.log(strGetter());