score:242
Use string concatenation:
href={'/posts/' + post.id}
The JSX syntax allows either to use strings or expressions ({...})
as values. You cannot mix both. Inside an expression you can, as the name suggests, use any JavaScript expression to compute the value.
score:0
Could you please try this ?
Create another item in post such as post.link then assign the link to it before send post to the render function.
post.link = '/posts/+ id.toString();
So, the above render function should be following instead.
return <li key={post.id}><a href={post.link}>{post.title}</a></li>
score:10
In addition to Felix's answer,
href={`/posts/${posts.id}`}
would work well too. This is nice because it's all in one string.
score:99
You can use ES6 backtick syntax too
<a href={`/customer/${item._id}`} >{item.get('firstName')} {item.get('lastName')}</a>
Source: stackoverflow.com
Related Query
- How to create dynamic href in react render function?
- How to fix TypeError _interopRequireDefault is not a function in Create React App
- How to provide dynamic className to element in React Class render method
- How to not use setState inside render function in React
- How to Separate Jsx inside render function into a separate file in ES6? or any other solution in react to separate the Logic and presentation?
- How i can create the function for the countdown in React native?
- How to access new props.value before render function in React life cycle
- How to create dynamic form input fields in React with ANTd
- How to create a React render condition for 3 options
- How to create a dynamic array of React hooks for an array of components
- How to use Bootstrap Modal inside map function in React Js to render indivisual elements?
- How can you render a react component using dynamic name?
- How to create a dynamic table in React JS depending on keys?
- How to render react component inside function in another component?
- React - How to render components inside a function outside of render plus execute same function outside of render?
- How do I create dynamic forms which can be changed from state in react js?
- how to pass variable from a function to render function in react
- React how to render dynamic images inside nested data objects
- How can I selectively render code in a Create React App SPA?
- Create a dynamic onClick function in React
- How to dynamically create and render JSX elements, defined from this.props with react
- How to create dynamic MUI Radio in Formik React form
- How to render a dynamic form in React
- How to create dynamic meta tags from client side in react node js project?
- How to create my own onChangeComplete function for input type color on React
- How to pass a javascript-generated DOM element to react render function
- How to render React Child Components from a function call?
- How to create a function that doesn't do anything in React
- How to create dynamic search filter in react JS?
- How to use calc css function in react render
More Query from same tag
- Using data from one component in another in Reactjs
- React too many re-renders when create an array with UseState
- Apollo client issues in next.js , javascript, graphql, react js
- Can not .map 2 different arrays in same table row, <tr>
- React useEffect Missing Dependency
- FirebaseErrorr: Missing or insufficient permissions happens, When trying to get snapShot
- Filter by ID using PokeAPI React
- Ternary expression translation with i18next react js
- Enzyme does not reflect state update
- React Router 4 Nested Routes not rendering
- Using API keys in a react app
- Nextjs hot reloading taking 8-10 secs on every change of tailwind css
- Date picker localization in material-table(Material UI)
- Get indian current time and date
- Trying to modify a data from a React Promise Response changes globally
- Firebase Authentication - User object becomes null only after first successful signup
- React app runs on Chrome but displays a blankpage on safari
- React Router v6 redirect when there are not any url queryString parameters
- Can't center and space card deck for react js bootstrap
- How does react redux promise middleware send the resulting action to the dispatch?
- Destructuring props in ReactJS
- Handling multiple instances of the same component in Flux
- tailwind error: Expected a pseudo-class or pseudo-element
- Best practices: Folder structure for client and server using create-react-app
- truncate text in reactJS
- React Router - get URL params outside of page component (inside of layout footer)
- Socket IO Server is Sending Messages But Client is not Receiving the Message
- EventEmitter.prototype in reactjs, this.on is not working and says it's not a function
- How can i give style to the ul inside the pagination
- How to set border to FloatingActionButton material ui