Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing componentWillReceiveProps by componentDidUpdate #83

Closed
wants to merge 2 commits into from
Closed

Replacing componentWillReceiveProps by componentDidUpdate #83

wants to merge 2 commits into from

Conversation

IamFonky
Copy link

@IamFonky IamFonky commented Sep 18, 2019

Seem to work fine without warnings now fixes #82

@leefsmp
Copy link
Owner

leefsmp commented Sep 18, 2019

The proper way to migrate from componentWillReceiveProps is actually to use the new getDerivedStateFromProps method. See here for more info.

Even if replacing with componentDidUpdate works, I don't think it is an optmized way of doing things.

@IamFonky
Copy link
Author

Thx for your review @leefsmp. I started using React with hooks and I'm not very good with React classes lifecycles.
I use getDerivedStateFromProps for the ReflexContainer but I read that it's better to use componentDidUpdate with data fetching.

facebook/react#13541

Is this better?

@leefsmp
Copy link
Owner

leefsmp commented Sep 18, 2019

I took a closer look at using getDerivedStateFromProps and in the current state of the code it require a lot of modifications inside ReflexContainer and it is also tricky because this is a static method, so it doesn't have access to ReactDOM.findDOMNode so I would need more time to migrate to it.

I was publishing v 3.0.17 with a similar fix than what you did in this PR but it actually breaks my own app where the layout is significantly more complex than in the demos, including some animations with the panes.

I will need more time to see how I can migrate to getDerivedStateFromProps in a proper way.

@leefsmp leefsmp closed this Sep 18, 2019
@IamFonky
Copy link
Author

Ok!
Do you want me to try with hooks?

@leefsmp
Copy link
Owner

leefsmp commented Sep 18, 2019

btw - I replaced componentWillReceiveProps by UNSAFE_componentWillReceiveProps which hopefully suppresses the warnings in v3.0.18.

Feel free if you want to try hooks but the internal logic in ReflexContainer is a bit tricky, you need to make sure you understand correctly what's going on otherwise complex use of the component in some layouts will break.

@IamFonky
Copy link
Author

Allright thank you for your help!
I'll try that soon.

@leefsmp
Copy link
Owner

leefsmp commented Sep 18, 2019

There is no async data fetching here as the layout computes it's state directly from the props but what is more complex than in other react components is that the logic has to solve some constraints to compute correct size of each element and it also has to access the DOM element to find out the size of the container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warning: componentWillReceiveProps has been renamed, and is not recommended for use.
2 participants