'Why useRecoilState return outdated data
I have React component like this:
import { useRecoilState} from 'recoil';
import { inputText } from './globalState';
export const Input = () => {
const [text, setText] = useRecoilState(inputText);
const handleOnChange = async (event) => {
setText(event.target.value)
console.log(text);
}
return (
<input value={text} onChange={handleOnChange} placeholder='blabla' />
)
}
Also I have global state for recoil purpose:
import { atom } from 'recoil';
export const inputText = atom({
key: 'input',
default: ''
})
My question is, why console.log returns old value of input?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
