score:6
Accepted answer
With your setImages({ images: imageArray })
call, you'll get value of images
const to be:
images = {images: [...]} // [...] is the imageArray
so you'll have to access it as images.images
, or rather set it as setImages(imageArray)
which will be accessible as you expect.
Also, access the state variable and use map
instead of forEach
, not the imageArray
. So instead of imageArray.forEach(...)
use images.map(...)
. Map returns an array with values returned from the function calls. Whereas forEach
returns undefined.
score:0
{imageArray.length>0 ?
<div>
{imageArray.map((element)=>{
return(
<img src={element} alt="" />
)
})}
</div>
:null}
Hope this solves
Source: stackoverflow.com
Related Query
- Getting an error that images is null while trying to show a preview of the uploaded images in react js
- Getting this error , when trying to upload images through a form "TypeError: Cannot read property 'originalname' of undefined "
- I am getting an error while trying to make a POST request of the "workout" object
- Error while trying to use the following icon from the Manifest
- Getting an error trying to start React right after (There might be a problem with the project dependency tree....)
- Error while trying to access files in the app
- Getting error "Cannot update a component while rendering a different component". What is the correct way to achieve what I'm attempting?
- Getting 404 error while call oAuth2 api in the browser
- Getting error while opening Google Drive Picker - The feature you requested is currently unavailable. Please try again later
- Show an error to upload the file or disable de button
- Object is possibly null error (typescript) when trying to display the value of an array which is stored in localstorage
- Trying to integrate jest and react with amchart but getting an error . What could be the issue?
- How to solve an error while trying to npm i the modules in a React project
- map() method on multi dimensional array in gatsby/react, getting error while trying to wrap inner loop in div
- Getting error when trying to print out an object that has an array
- Getting an error while trying to access nested objects in Reactjs
- Why am I getting undefined while trying to filter the movie release_date?
- Getting a different port ERROR in the console while uploading image from the frontend using react js to the Mongo db
- Using Map and Sort to show the objects that contains URL of images with the timestamps
- Getting image.map is not a function error while trying to render search list
- getting "params.Body is required" error when trying to upload to s3
- Getting error while trying to render array of object in react js
- I am getting an error in the JSX while calling a function inside it
- when am trying to upload excel sheet it will uploaded successfully but am getting an error undefined offset: 500 in line 159
- Getting error while trying to loading a react-leaflet map
- getting error while destructuring the data from react redux. why it is giving error and how to solve this?
- function returning the data to filter and map that show error React.js TypeError: Cannot read property 'val' of undefined
- I have 2 components and I want a 3rd component to show animation while waiting for the 2nd one to load images
- Getting error while closing the react-modal
- I want to show all image preview but whenever I upload a new one the old one is gone
More Query from same tag
- Post Request from axios always returns Unauthorized despite having valid JWT set in header/Axios Deletes Headers
- I get a undefined in my React API component
- ReactJS - Undefined when accessing data from API
- Javascript - How to loop through an array over and over again in React
- React default function
- PureComponent vs Component
- Calling UseEffect several times causing problems
- How to put one whole class to the right ? / how to add padding in class? - confused ( React.js - Bootstrap)
- Multiplying Row.values and user input values in Reactjs tables
- Why Native DOM event always reset React Component state
- Material UI / material-ui appbar leftnav toggle not working
- can we pass props to another react router page without context and redux?
- Problems with Rendering Component in React + Typescript
- How to display data according to query string using ReactJs?
- How to show dialog after successfull API call in react?
- React JS Removing specific item from list
- How to place Search Bar inside header in React Native?
- react hooks question: simple content filter
- Can't verify email and password from Firebase
- Material UI V5 Theming Customization
- Ant Design Upload: preview one image only?
- React chartjs 2 - Type 'string' is not assignable to type '"timeseries"'
- Resolving Elements in Array when Array Length is 0 (MongoDB, React, Axios)
- Override component styles via Box
- React JS - Expected `onClick` listener to be a function, instead got a value of `string` type
- How to select area on React Leaflet Map using external Select dropdown component
- onBlur event not allowing link clicks to register
- how can we use data received through axios put request on client side in mern stack?
- Make react components less verbose
- Unit Test: How to mock specific function with jest?