#Need some help trying to figure out how to pass URL prop for component displaying fetched data

23 messages · Page 1 of 1 (latest)

stray tangle
#

Yes getStaticProps is only part of nextjs, so if you are not using it, it wouldn’t be available

#

Need more information to understand what you are trying to do

#

Like how is the user gonna enter the URL and anything else that could possibly help

past dagger
#

So user starts off with a form to enter URL, url gets passed in to fetch data. Then once data is fetched, I want to use the LinkMetadata component to display it by the entered URL if that makes sense.

The button and input form are set up, but I can’t figure out how to make the component pass a URL prop that fetches data from the url

stray tangle
past dagger
stray tangle
#

Which part is it that isn’t behaving correctly

#

It’s a bit difficult if there’s no error and I can’t run the code

past dagger
#

The fetch request is fine if I ignore the other parts and try to get the data out it works. I think my logic doesn’t make sense for what I’m trying to do

#

This is the API I’m calling it from, https://jsonlink.io/api/extract?url= and I want the URL to be passed in the LinkMetadata prop so I can populate the metadata information I get from the fetch

stray tangle
#
    try {
      setError(null)
      const metadata = getMetaData(url)
      setMetadata((metadata) => 
        {
          title: metadata?.title,
          description: metadata?.description,
          images: metadata?.images[],
          domain: metadata!.domain,
          url: metadata.url,
        }
      )
    } catch (error: any) {
      console.log('error', error.message)
      setError(error.message)
    }
  },[])```
past dagger
#

hmm, didn't seem to work, says my title, description, ... are undefined

stray tangle
stray tangle
past dagger
#

ahh I changed the getStaticProps because someone said it wasn't useable if it's not within Pages, but found that I can actually use it

stray tangle
past dagger
#

so I can replace it with a function like getMetadata?

past dagger
#

I think I figured it out with using the useEffect hook