score:0
Accepted answer
in here
result.foreach((el) => {
if (el === "undefined") {
return;
} else {
console.log(el) // this provides the correct values
setnearestplace(el); // here is where it wont set my state to the values
console.log(nearestplace);
}
return el;
});
you are calling setnearestplace()
in a loop and passing the array element as an argument. as a result, the last value passed, i.e. the last element of the array will be your final state.
i believe you are trying to do something like this instead
setnearestplace(result.filter(ele => boolean(ele))); // boolean(ele) check whether the ele is null or undefined.
Source: stackoverflow.com
Related Query
- Showing users nearby locations based off radius
- how to get multiple nearby locations based on rank using haversine reactjs
- How to render different components based off device size?
- When I turn off the internet connection it's not showing false value from NetInfo.isConnect function
- Showing elements based on ternary operator
- Reactjs - How can I create a Boolean based off a successful axios POST?
- Showing / Hiding links based on criteria: React+Typescript
- How to change a className of a particular element based off it's child input value and input dataset comparison?
- 3rd dropdown is based off first 2 dropdown's selections but the 3rd's state is always 1 step behind
- Dynamically creating a new component based off another component's state
- Looping over an array of objects and showing values based on static keys defined javascript
- Read Dynamic Height of Inner Components Off Children in .map() and Set New Height in Outer Components based on Inner Components Height
- ReactJs hook reducer filtering through array based off user string input
- how do i create a new object based off an array and another object?
- How to pass down certain props based off of certain screen size
- How can I use react-zoom-pan-pinch to allow users to view all of a chart that changes size based on user input?
- React: How to alert a list, based off the value of inputs
- Unable to render a component based off function
- set state based off option value in a select
- How do I change an object attribute based off of a path property array in another object?
- How to sort an array based off an array of indexes that are in order?
- How do I set the width of a component in my React web-app based off the output of a variable
- Call Object based off of string
- Inline style based off JSON value React
- React - How can I get pagination to re-render based off amount of objects per view selected via user-input?
- Setting input props based off another prop state?
- Unable to render image based off prop from axios call in React web app
- React: Conditionally render a component in a route based on login status, without showing loading page
- Showing elements based on authentication status in ReactJS
- Splice data based off page
More Query from same tag
- "You may need an appropriate loader to handle this file type"
- Material-UI Theme Override Issue
- How can I do to display my search bar using react-leaflet?
- Counter no less than 0 using react hooks
- Ionic ReactJS Binding element 'appProps' implicitly has an 'any' type. TS7031
- Nginx/React/Django: CORS issue
- I can't seem to display the background image. The background Image shows up for a split second but then crash 'failed to execute CreateElement'
- React - How to add multiple values for a the state
- Node + react js increse upload file size in post request
- SCSS styles imported to components in app.js are being applied to all components in app.js
- How to make certain <div>'s appear/disappear on category selection | ReactJS
- i18n react return [object object]
- React Router rendering only base path (/) and throwing error for other paths when requested directly in the browser
- Passing handleSubmit() to child component does not modify parent's state
- Why is React Bootstrap Card not showing in the browser? The page is empty despite the component being used
- Pass extra parameter with the react router definition
- React: Prevent MUI Draggable Dialog From Going Off Screen
- Webpack css-loader does not consider localIdentName
- React-select container option width
- How to reduce and get value from object array using javascript
- How to access React Context outside of component?
- Passing props to parent
- React multiple output files of bundle of single Input file
- How to cleanup PixiJS references on browser window close?
- Call function inside component from different component
- React component name in Higher Order Component
- Cannot stop recursive setTimeout function in my react electron screen tracker app
- Passing Gatsby Image As Prop
- Fake server response body should be string, but was undefined
- multiple conditional renderings inside a map function