6

I'm trying to figure out if this is a react-router thing or just a React thing. I am talking about the $ here in their example:

react-router API

<Link to={`/users/${user.id}`} activeClassName="current">{user.name}</Link>

is the ${} a react thing? and if so what do you call it?

PositiveGuy
  • 17,621
  • 26
  • 79
  • 138

3 Answers3

19

This is not a React thing.

This is a JavaScript ES6 feature:

The old way to concatenate a string :

var user = 'abc' + myuser;

ES6:

var user = `abc${myuser}`;
Kevin He
  • 871
  • 7
  • 18
2

${variableName} inside backticks is just part of es6's string interpolation system that simply just embeds the value of a variable in the given string.

For more docs and examples see MDN - Template Literals

Ties
  • 806
  • 7
  • 13
2

the ${} is the syntax for variables (or other code to be executed) inside template literals (`).

read up about template literals here: mdn

Haroen Viaene
  • 1,329
  • 18
  • 33