So I've retrieved data in JSON
format using GET
request then I'm facing a problem in saving into my state
so that I can display them into my span
/div
/h1
using map function
. Here's how my JSON
data looks like:
[
{
"projectName": "SHIBA INU",
"projectToken": "SHIB",
"tokenPrice": 0.2,
"saleStart":{
"$date": "2021-12-20T20:00:00.00Z"
},
{
"projectName": "BITCOIN",
"projectToken": "BTC",
"tokenPrice": 200,
"saleStart":{
"$date": "2021-12-20T20:00:00.00Z"
}
]
So I'm trying to do this way but I dont think it will work:
const [projectData, setProjectData] = useState({})
useEffect(() => {
axios.get(`my api`).then(res => {
for(let i=0; i<res.data.length; i+1){
setProjectData(...projectData, res.data[i])
}
}).catch(e => console.log("error: ", e));
},[]);
I'm not sure whether I should save them into an array or an object