Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-router what is $?

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?

like image 358
PositiveGuy Avatar asked Jun 05 '16 06:06

PositiveGuy


People also ask

What is * in react router dom?

Using an asterisk ( * )To set up a default page in React Router, pass an asterisk ( * ) to the Route 's path prop: <Switch> <Route exact path="/" component={Home} /> <Route path="/messages" component={Messages} /> <Route path="/about" component={About} /> <Route path="*" component={Home} /> </Switch>

What is BrowserRouter in react react router dom?

React Router is a standard library for routing in React. It enables navigation between views from different components in a React application, allows the browser URL to be changed, and keeps the UI in sync with the URL.

What is routing in react?

Routing is a process in which a user is directed to different pages based on their action or request. ReactJS Router is mainly used for developing Single Page Web Applications. React Router is used to define multiple routes in the application.

What is ID react router?

Use the useParams() hook to get the ID from a URL in React, e.g. const params = useParams() . The useParams hook returns an object of key-value pairs of the dynamic params from the current URL that were matched by the Route path.


2 Answers

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}`;
like image 164
Kevin He Avatar answered Oct 05 '22 11:10

Kevin He


${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

like image 42
Ties Avatar answered Oct 05 '22 12:10

Ties