score:0
Accepted answer
you should return an expression when you use that condition :
const restaurantlist = restaurante.map((restaurant) => (name=="something" ?
<restaurant
src={background}
key={restaurant.id}
restaurant={restaurant}
/>:null
));
or
const restaurantlist = restaurants.map((restaurant) => {
if(name=="something"){
<restaurant
src={background}
key={restaurant.id}
restaurant={restaurant}
/>
} else{
return null;
}
});
Source: stackoverflow.com
Related Query
- if else statement in map function reactjs
- ReactJS syntax for if else with map function in branch
- "this" is undefined inside map function Reactjs
- How to do a nested if else statement in ReactJS JSX?
- Reactjs map works but forEach doesn't
- Reactjs how to use ref inside map function?
- filter vs map reactjs and jsx
- How can I use Esri Arcgis Map in ReactJs Project?
- How to map inside a map function in reactjs
- Mapbox blank map React-map-gl | ReactJS
- how to update input text which is render by array map in REACTJS
- ES6 array map doesn't return anything: ReactJS
- How to set a defaultChecked to only first input in radio button when using map function in reactjs
- Debugging ReactJs in Chrome on page load - this and everything else is undefined when using console
- error map in missing props reactjs proptypes
- Leaflet ReactJS Map does not show tile completely
- How to use this highchart map in reactJS
- How to update state in map function in reactjs
- reactjs how to call method inside map function
- How to run map inside map function in Reactjs
- Reactjs condition inside map function
- Loop an array index inside a map in ReactJS
- reactJS dynamic drop down populated with map function
- How to map images in reactjs
- Displaying array of objects using map in reactJs
- How to map inside map function and show the data in Reactjs
- Reactjs handleclick binding in a nested map not working
- Uncaught TypeError: map is not a function In Reactjs with Firebase
- ReactJS - nested loops with map js
- Map an array of arrays with ReactJS
More Query from same tag
- React component lifecycles still run after redirect
- Removing multiple objects from Redux state array
- react-hook-form Controller issues
- Why am I overwriting all of my values in state with my object spread?
- Spread operator with React useState // Populating state from Firebase
- Count occurrences in strings of an array of objects in Javascript
- save the previous state to one array in ReactJS
- Uncaught TypeError: Cannot read property 'map' of undefined in reactjs even when using it on array
- React Hooks Scroll to Element
- Call an ActionCreator from another ActionCreator
- Add an array of Objects to a mutation in apollo-react
- How to move marker on the google map react js
- How to add the payload to the root of a slice in the extraReducer in React Toolkit?
- React state returns undefined when passed as object value
- Protected Route With Firebase
- how to use static data in react
- Dockerfile not working on backend with react
- How can I append a tab everytime I click in react?
- What is Parsing error: Invalid escape sequence in template?
- Sorting number with comma in react-bootstrap-table2
- React app not working in Internet Explorer 11
- Start a cloned create-react-app from Github
- Create a multilevel dropdown dynamically in React and get the value of selected submenu in dropdown
- Using form labels for multiple elements
- React Router: access history in rendered Route component
- React component library can not load its own static asset
- How to get updated props in setInterval by using react hooks?
- Add HTML property conditionally in React
- Routing by item id using React Router
- Unexpected behavior of useCallback hook in my React component