-1

So I have a JSON where I'm fetching data.

Example of JSON:

 { "postid": "123123, "title": "title of post", } 

I'm trying to add this id inside an href like <a href="https://example.com/{data.post}">Post</a> but it doesn't render, I get a https://example.com/{data.post} url in the frontend. (Doing <p>{data.post}</p> renders the post ID normally.)

Is there a way to get the field inside an href tag? Or should I make another field on my JSON with the full URL?

0

1 Answer 1

0

Pass in a template literal as a normal value:

<a href={`https://example.com/${data.post}`}>Post</a> 

Please see these docs on how to pass attributes to a JSX element. The above is just simply a Javascript tempalate liter passed in as a prop to the <a> tag.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.