axios.get first time response is empty using useState and useEffect

I dont know why first time response is empty, I have tried several ways, using loading and without , using ... thing also. can someone help me out what am I doing wrong ? No idea even why I get console 2 or 3 times even [here is my console][1]

    const Product = (props) => {
        const artikeId = props.match.params['number'];
        const [productData, setProductData] = useState([]);`enter code here`
        const [loading, setLoading] = useState(false);

        useEffect( () => {
            const fetchData = async () => {
                await axios.get(`http://localhost:8081/products/${artikeId}`)
                    .then(res => {
                        setProductData(res.data)
                        setLoading(true)
                        //    setProductData([...productData,res.data]);
                    })
            };
            fetchData();
        }, []);

        console.log(productData)

        return <div>
If it works I will return {productData[0].name} etc etc
        </div>
    }
    export default Product```


  [1]: https://i.stack.imgur.com/U58JI.png

29 thoughts on “axios.get first time response is empty using useState and useEffect”

  1. therapies cognitivo-comportementales paris pharmacie de garde epinal , pharmacie de garde jura therapie sexofonctionnelle , [url=https://kit.co/niufran/acheter-renagel-800-mg-pas-cher-renagel-prix-sans-ordonnance#]Renagel sans ordonnance Belgique[/url] pharmacie becker monteux societe.com [url=https://kit.co/omca/prednisone-vente-libre-acheter-prednisone-40-mg-pas-cher#]Prednisone sans ordonnance QuГ©bec[/url] , therapies breves vannes pharmacie bordeaux grand parc , therapie quantique formation. pharmacie aix en provence pont de l’arc therapie comportementale et cognitive haute savoie [url=https://kit.co/outber/lioresal-livraison-france-lioresal-vente-libre#]Lioresal sans ordonnance France[/url] , traitement insuffisance cardiaque. pharmacie ouverte quebec, therapie de couple exercices chu amiens pharmacie essais cliniques . pharmacie de bourges, therapies used for ptsd act therapy in a nutshell therapie comportementale et cognitive valence .

    Reply

Leave a Comment