Categories
React Answers

How to create dynamic href in React component?

Spread the love

Sometimes, we want to create dynamic href in React component

In this article, we’ll look at how to create dynamic href in React component.

How to create dynamic href in React component?

To create dynamic href in React component, we can use template strings.

For instance, we write

<a href={`/customer/${item._id}`}>
  {item.get("firstName")} {item.get("lastName")}
</a>;

in our component to set the href prop to the string returned by /customer/${item._id}.

Conclusion

To create dynamic href in React component, we can use template strings.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.