Answer the question
In order to leave comments, you need to log in
Why doesn't setState change in if?
how to make it so that it does not return empty but full?
const customHook = () => {
let [state, setState] = useState('пустой');
let arr = [1, 2, 3 ];
if(arr.length > 1) {
setState('полный');
console.log(state) /* пустой */
}
if(arr.length < 1) {
setState('пустой')
}
return {arr} /* пустой */
}
export default customHook;
Answer the question
In order to leave comments, you need to log in
first link in google
try this
const customHook = () => {
let [state, setState] = useState('пустой');
let arr = [1, 2, 3 ];
if(arr.length > 1) {
setState('полный', () => {
console.log(state)
});
}
if(arr.length < 1) {
setState('пустой')
}
return {arr} /* пустой */
}
export default customHook;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question