Answer the question
In order to leave comments, you need to log in
UseState React not updating data?
const [lists, setLists] = useState(null);
useEffect (() => {
async function getUser() {
try {
const response = await axios.get('http://localhost:3001/lists');
const {data} = response;
setLists(data);
console.log(lists);
} catch (error) {
console.error(error);
}
}
getUser()
axios.get('http://localhost:3001/lists').then(({ data }) => {
let list = data;
setLists(list);
});
}, [])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question