1

Currently receiving a error stating Cannot convert undefined or null to object

The data the app is looking for comes from initial props. I assume on the initial check no data is present, so it throws that error.

Would this be solved with an async/await ?

The initial posts_mentions is defaulted as an empty object

Here is the error image: enter image description here

Here is the current code snippet

const { posts_mentions: postsMentions } = useData();
    const data = Object.keys(postsMentions).map(label => {
        return {
            name: shortName(label),
            posts: postsMentions[label].posts,
            mentions: postsMentions[label].mentions
        }
    })

2 Answers 2

1
async function something(){
const { posts_mentions: postsMentions } = await useData();
 const data = Object.keys(postsMentions).map(label => {
    return {
        name: shortName(label),
        posts: postsMentions[label].posts,
        mentions: postsMentions[label].mentions
    }
})

}

Sign up to request clarification or add additional context in comments.

1 Comment

If this doesnt work than you need to share your code for useData function. But other than that when you console.log(posts_mentions) it shows you something right?
0

Yes. Try adding await before useData(). And if this is all part of bigger function than mark it as async. How does the useData() look? Is something async in it?

1 Comment

the initial data is being pulled in with async call when the app is loaded. can you provide an example of how useData() would look with async ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.