Answer the question
In order to leave comments, you need to log in
How to pass a new state to a function in react?
Good afternoon, there is an application written in React:
const App = () => {
const [status, setStatus] = useState(null)
function getStatus() {
console.log(status)
}
}
useEffect(() => {
// ...
}, [status])
Answer the question
In order to leave comments, you need to log in
There is essentially only one option, probably - to save the state in ref.
But you still have to update the ref in useEffect :
useEffect(() => {
ref.current = status;
}, [status]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question