TypeError: Invalid attempt to spread non-iterable instance

This is because it is a runtime error, not a “compile time” error. Is there a line number associated with the error? Based on the question being about the spread operator I’ll assume it’s this line: newArticlesData=[…prevData,…response.data]. I assume your prevData is iterable, but is your response data? Try newArticlesData=[…prevData, response.data]? Here’s an example of invalid spread operator use:

Is using async componentDidMount() good?

Let’s start by pointing out the differences and determining how it could cause troubles. Here is the code of async and “sync” componentDidMount() life-cycle method: By looking at the code, I can point out the following differences: The async keywords: In typescript, this is merely a code marker. It does 2 things: Force the return type to be Promise<void> instead of void. … Read more

When to use useImperativeHandle, useLayoutEffect, and useDebugValue

Allow me to preface this answer by stating that all of these hooks are very rarely used. 99% of the time, you won’t need these. They are only meant to cover some rare corner-case scenarios. useImperativeHandle Usually when you use useRef you are given the instance value of the component the ref is attached to. This allows you to … Read more

React Navigation back() and goBack() not working

The key property for goBack() is a dynamically created string, created by react-navigation whenever it navigates to a new route. for example:  It is stored in this.props.navigation.state.key. So if you want to go from EditPage to Cover, what you have to do is to pass the key of EditCover down to EditPage, and then call goBack() with the key. Why not key of Cover but EditCover? Because react-navigation only provides the method goBack(key), it’s go … Read more

react-native: command not found

After adding right path to the PATH variable issue is resolved. Below are the steps to find the right path. from above output you can clearly see the path: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native if you getting xcrun: error: unable to find utility “simctl” at this stage you can reslove using below steps XCode -> Preferences -> Locations -> Command Line Tools … Read more

What is prevState in ReactJS? [duplicate]

prevState is a name that you have given to the argument passed to setState callback function. What it holds is the value of state before the setState was triggered by React; Since setState does batching, its sometimes important to know what the previous state was when you want to update the new state based on the previous state value. So … Read more