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)

16 Libraries You Should Know as a React Developer

Being a modern React developer is not about knowing just React itself. To stay competitive, it is highly recommended to explore the whole ecosystem. This article contains some of the most useful React component libraries to speed up your developer workflow.