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

fix: 🐛 use constructor() instead of UNSAFE_componentWillMount() #63

Closed
wants to merge 1 commit into from
Closed

Conversation

streamich
Copy link

Closes #62

@streamich
Copy link
Author

This change should hopefully remove console warnings like below.

image

@andreyluiz
Copy link

I am very interested on this PR too. @gaearon, can you see it, please?

@lourd
Copy link
Collaborator

lourd commented Jan 6, 2020

Hey y'all, thanks for the PR!

I'm concerned that this change may create a bug regarding side effect ordering. The tests don't currently cover the behavior, but please refer to this discussion for more context.

Could you please add some tests that cover nesting order to demonstrate that changing from componentWillMount to the constructor won't break anything? I know that's asking a lot more, but it would really help.

@@ -67,7 +67,8 @@ export default function withSideEffect(
return recordedState;
}

UNSAFE_componentWillMount() {
constructor(props, context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this should be in the constructor instead of componentDidMount? Ideally, constructors should not have side-effects

@gaearon
Copy link
Owner

gaearon commented Jan 22, 2020

Thanks for the PR, but this doesn’t fix anything. It just silences the warning. Side effects in constructor are exactly as bad as in componentWillMount.

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.

Replace UNSAFE_componentWillMount with constructor
5 participants