DEV Community

Discussion on: Let's build a search bar in React!

Collapse
 
machy44 profile image
machy44 • Edited

Nice Article.

When I use getDerivedStateFromProps() in same way you use componentWillReceiveProps() in List component searching doesn't work.

static getDerivedStateFromProps(nextProps) {
return {
filtered: nextProps.items
};
}

I didn't know that getDerivedStateFromProps is called every time we setState(). Link for lifecycles projects.wojtekmaj.pl/react-lifecy....

I wanted to share this thought with you cause I didn't give enough attention about differences between componentWillReceiveProps and getDerivedStateFromProps and IMHO this is kind of important.

Collapse
 
iam_timsmith profile image
Tim Smith

This is awesome! Thanks for the link!

Collapse
 
machy44 profile image
machy44

Np. Thank you for the article