Currently trying to map over an array that has multiple nested objects. When I run the map function, it only returns the outer object.
const [moreDetails, setMoreDetails] = useState([]);
const [details, setDetails] = useState("");
const handleAddMoreDetails = () => {
setMoreDetails((prevState) => [
{
...prevState,
details: details
}
]);
setDetails("");
};
return (
<div className="App">
<input
type="text"
value={details}
onChange={(e) => setDetails(e.target.value)}
/>
<button onClick={handleAddMoreDetails}>Add Detail</button>
{moreDetails &&
moreDetails.map((item, index) => <p key={index}>{item.details}</p>)}
</div>
);
This is similar to what I am trying to accomplish. I would like for it to render all of them when added. I am thinking it may be the one I am trying to add a new detail

itemin each iteration? Is it really an object as you claim? If it is an object, what are its keys? Are they what you expect? The screenshot of the structure ofmoreDetailsdoesn't seem to match what you think it is and you need to figure out why.