0

Why doesn't the "product" state change in this function? I am getting data to display in a table. But this data is not displayed because the product state is not updated.

  const [datos, setDatos] = useState([]);

  useEffect(() => {
    const fetchDatos = async () => {
    try {
        const response = await axios.get(`${process.env.REACT_APP_API_URL}/data`);
        setDatos(response.data);
        console.log(datos)
    } catch (err) {
        console.log(err.response.data)
    }
}
fetchDatos();
  }, []);
  

I'm trying to display the "producto" data in a table but it's not showing anything because the "producto" state is not updated in time. The data comes from my MongoDB database. what am I doing wrong?

Carlos K
  • 3
  • 2
  • Does this answer your question? [The useState set method is not reflecting a change immediately](https://stackoverflow.com/questions/54069253/the-usestate-set-method-is-not-reflecting-a-change-immediately) – Ahmed Sbai Apr 01 '23 at 00:13

0 Answers0