I want to know why it returns a log <empty string>
when I already assigned a value using setState
. Does the setState
not working? Please help me to fix it.
Here is my code:
const App = (params) => {
const [data, setData] = useState('');
const getDatas = async (params) => {
const { data } = await http().get('todo');
setData('new data');
}
useEffect(() => {
getDatas();
console.log(data);
}, []);
return (
<div className="border">Display text</div>
);
}