Bug in my first Api project

would someone please help
when i write a link to be shortened it gives me the previous result. I want to understand why?

this is my first time building a website with api so any recommendation for improving are welcome

live site: https://shorty-url-shortening-api.vercel.app/
repo: GitHub - onna4/shorty-URL-shortening-API: shorty URL shortening API built with react

i used useEffect with fetch to get the data. and I’m storing it in localStorage

first of, cool design :sunglasses:

useEffect(() => {
    localStorage.setItem("linkData", JSON.stringify(dataArray))

  }, [dataArray])
  • you need to re think your “useEffect” dependency to trigger to get recent data

to me, currently it seems like its always going to be “same data” unless your “components are re-rendering” after each form submit

hope this helps, happy coding :slight_smile:

1 Like

well i’m updating the state of dataArray and it suppose to trigger a re-render in the app… why it acts like that? when I console log the dataArray it gets the updated data but the one in local storage isn’t updates.

  • can you share that piece of code where you are updating “localStorage”
  • maybe you can alternatively work with “dataArray” instead, just a though :slight_smile:

happy coding :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.