DEV Community

Joney Spark
Joney Spark

Posted on

how to push a array element in a single array object in react.js ? Help Plz

let {postDetail} = useParams(); const url = `https://jsonplaceholder.typicode.com/posts/${postDetail}`; const [details, setDetails] = useState([]); useEffect(()=>{ fetch(url) .then(res => res.json()) .then(data => { setDetails(data => [...data, {"image":`${data.id}`}]); }) },[]); 

Top comments (0)