Use async/await in getDerivedStateFromProps
See original GitHub issueHi I’m in need of aysnc/await in getDerivedStateFromProps but it’s not working as expected.
static getDerivedStateFromProps(props, state) {
const response = [];
console.log('break 1');
[1, 2].map(async path => {
console.log('break 2');
const data = await FileGetData.get(path);
response.push(data);
});
console.log('break 3');
return { fileData: response };
}
Expected
break 1
break 2
break 2
break 3
Results:
break1
break3
break2
break2
Can’t we use async/await in getDerivedStateFromProps?
Thanks,
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
reactjs - Calling a asynchronous function inside ...
So I tried to call a function update inside getDerivedStateFromProps but it seems like I can't use 'this' inside getDerivedStateFromProps.
Read more >Update on Async Rendering – React Blog
The new static getDerivedStateFromProps lifecycle is invoked after a component is instantiated as well as before it is re-rendered. It can ...
Read more >How to use async/await in React props | by Mudafar El Halabi
How to use async/await in React props. A new way for bi-directional communication between react components.
Read more >Rendering and Updating Data using Component Lifecycle ...
1async getTodos() { 2 let data = await axios 3 .get("https://jsonplaceholder.typicode.com/todos?_limit=10") 4 .then(function(response) { 5 ...
Read more >AsyncButton | EF React Native Asynchronous Button
Note: the presence of getSnapshotBeforeUpdate or getDerivedStateFromProps prevents this from being invoked. deprecated. 16.3, use componentDidMount or the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Don’t use
getDerivedStateFromPropsfor data fetching. It’s not meant for this.You want to put this logic into
componentDidUpdate.Client implementation is more or less ready. The cache provider still needs work but the core implementation is already in production at FB.
We’re just starting work on the SSR part. So it might come later.