score:0
Accepted answer
Try adding a return statement to your map function.
function marker(idx) {
return eventData.map((ev, index) => { //add return statement
if(ev.categories[0].id === idx) {
console.log(ev);
return <LocationMarker key = {index} lat={ev.geometries[0].coordinates[1]} lng={ev.geometries[0].coordinates[0]} onClick={() => {
setLocationInfo({ id: ev.id, title: ev.title });
//support for toggle away info box
setInfoBox(!infoBox);
}} />
}
return null
})}
score:1
You omitted to add return
statement in marker
function
You should add marker
to the function or convert marker
function to arrow one.
General function
function marker(idx) {
return eventData.map((ev, index) => {
if(ev.categories[0].id === idx) {
console.log(ev);
return <LocationMarker key = {index} lat={ev.geometries[0].coordinates[1]} lng={ev.geometries[0].coordinates[0]} onClick={() => {
setLocationInfo({ id: ev.id, title: ev.title });
//support for toggle away info box
setInfoBox(!infoBox);
}} />
}
return null
})
}
Arrow function
const marker = (idx) => eventData.map((ev, index) => {
if(ev.categories[0].id === idx) {
console.log(ev);
return <LocationMarker key = {index} lat={ev.geometries[0].coordinates[1]} lng={ev.geometries[0].coordinates[0]} onClick={() => {
setLocationInfo({ id: ev.id, title: ev.title });
//support for toggle away info box
setInfoBox(!infoBox);
}} />
}
return null
});
Source: stackoverflow.com
Related Query
- make a wrapper function around map in react
- How to make 3 column grid with map function react
- Render elements with a wrapper from a map function in react
- how to use map function to make const in react
- React Bootstrap make only one collapse open up when being rendered with a map function / display relevant information in each collapse
- how to make state work in only one div inside map function in react
- Render Content Dynamically from an array map function in React Native
- map function not working in React
- how to access vairables outside of map function in js and jsx in a React component
- React Native pass parameters through map function
- React onClick function in map function
- How to make React Create App Production Error Boundary map to source code
- How to loop inside map function using jsx format React JS
- React modal always take the last element of map function
- Why is only the last item in a map function being changed in react app?
- React - State Hook map is not a function
- React - State Hook map is not a function
- React won't render within map function
- React Higher Order Component - call function in the wrapped component from the wrapper component
- How to make key value of map function increment for each element in JavaScript
- React - mapping data to rows that are formed during a map function
- How to map an object's keys to make JSON easier to handle in React
- React input text default value and onblur function make input text read only
- React - Adding component in Map function not adding
- React - Render Item inside map function by click event
- React waiting for map function before deciding render to prevent div flash
- React onClick handler in map function
- A thin wrapper of ACE editor to make a React Component
- React JS printing data inside a nested map function in JSX
- How to use ES6 map function in React stateless component
More Query from same tag
- React - JSX is not changing on conditional rendering
- React: Find out if an element is inside another ref container
- PromiseĀ {<pending>} being returned and await key word not working
- I have an error about invalid useState hook in this case?
- Using css-loader inline with Webpack + React
- Mocking a function returned by a react hook
- How to get current provider of session in Next-auth
- ASP.NET Core with React template returns index.html
- react hooks: Can't create list with map function
- Read a File through FileReader Api and Convert it into json object
- react-rails asset pipeline image path
- React Toggle Functionality
- React navigation event listeners being called multiple times
- React Prop Becomes Undefined on Re-render
- React Rerun an animation every time a string update
- How to get component's id after clicking on it - react
- React Material-UI Grid System
- I am getting initialization error in the following react-redux code
- ReactJS - setState error when unMounting and Mounting
- Protected Route in React, not passing parameters
- Stuck at Whitescreen after building Ionic React android app
- On click on link should create/open an html page in react-hooks site with contents displaying
- How to passing refs to component in React
- Cannot access props from function inside React Component
- Reactjs - Multiple if conditions inside map function
- LocalStorage doesn't save on refresh
- How can I set react-particles-js as the background while using React?
- The auto prettier in Reactjs breaks the line
- Async Callback Execution After setTimeout Problem
- Subscriptions with react-meteor-data