Emotion: Stop using componentWillMount

Created on 7 May 2018  路  4Comments  路  Source: emotion-js/emotion

  • emotion version: 9.1.3
  • react version: 16.3

Relevant code.

        componentWillMount() {
          if (this.context[channel] !== undefined) {
            this.unsubscribe = this.context[channel].subscribe(
              setTheme.bind(this)
            )
          }
        }

What you did:
Update to React 16.3 and use strict mode.

What happened:
This warning appeared: componentWillMount: Please update the following components to use componentDidMount instead: Styled(div), Styled(li), Styled(span), Styled(ul)

Reproduction:
Just use styled within React strict-mode or React Async:
https://codesandbox.io/s/732mw5w53j


Problem description:
componentWillMount is going to be deprecated and should be avoided from now on.

Suggested solution:
This is the componentWillMount which is causing the warning:
https://github.com/emotion-js/emotion/blob/82fd71a8f9fda7df31b4810b17a255a75500686b/packages/create-emotion-styled/src/index.js

That logic could be moved to the componentDidMount or the constructor. Whichever is the case, let me know and I'll do a PR.

bug

All 4 comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

made PR #830 to fix this

As I mentioned in #830, this is going to be fixed in emotion 10.

Closing as fixed by Emotion 10

Was this page helpful?
0 / 5 - 0 ratings