useEffect(() => {
// declare the async data fetching function
const fetchData = async () => {
// get the data from the api
const params = {ethAddress: Address};
const data = await Moralis.Cloud.run('getFollowers', params);
const userdata= await Moralis.Cloud.run('getUser', params);
// convert the data to json
//const json = await data.json();
// set state with the result
setfollowers(data);
setiscurrentuser(userdata.username);{
for (let i = 0; i < data.followers.length; i++) {
// dict[res.data.followers[i].id]=1;
setfollowers_id(prevState => ({
...prevState,
[data.followers[i].id]:1,
}));
}
}
}
// call the function
fetchData()
// make sure to catch any error
.catch(console.error);;
}, [])
You can try to check the value of that variable.
Please help me …I am new to this …thank you
You can try to add some debugging with console.log
Please can you show me an example
An example: console.log(variable_name)
try to do as @cryptokid says and console.log(data.followers)
it must be undefined
I’m not very sure how you structure your state, but if you don’t initialize anything in useState
, then I also suggest you to initialize it with an empty array
1 Like