Skip to content

getInitialState isn't transformed into constructor this.state #75

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

Closed
petrbrzek opened this issue Aug 31, 2016 · 3 comments
Closed

getInitialState isn't transformed into constructor this.state #75

petrbrzek opened this issue Aug 31, 2016 · 3 comments

Comments

@petrbrzek
Copy link

Before:

let WorkspaceItemView = React.createClass({
  displayName: 'WorkspaceItemView',

  getInitialState() {
    return {
      workspaceItemManager: this._getWorkspaceItemManager(this.props.id),
      workspaceItemStore: this._getWorkspaceItemStore(this.props.id)
    };
  },
});

After: (that's how it works now)

class WorkspaceItemView extends React.Component {
  static displayName = 'WorkspaceItemView';

  state = {
    workspaceItemManager: this._getWorkspaceItemManager(this.props.id),
    workspaceItemStore: this._getWorkspaceItemStore(this.props.id)
  };
}

But it should be this:

class WorkspaceItemView extends React.Component {
  static displayName = 'WorkspaceItemView';

  constructor(props) {
    super(props);

    this.state = {
      workspaceItemManager: this._getWorkspaceItemManager(this.props.id),
      workspaceItemStore: this._getWorkspaceItemStore(this.props.id)
    };
  }
}
@cpojer
Copy link
Member

cpojer commented Aug 31, 2016

No, this is intentional. The new codemod expects you to use the class properties transform.

cc @keyanzhang

@cpojer cpojer closed this as completed Aug 31, 2016
@keyz
Copy link
Member

keyz commented Aug 31, 2016

Yeah, we don't need to create a constructor when the initial state is simple. The updated README explains how it works :)

@Misterhex
Copy link

Misterhex commented Jun 6, 2017

for those who needed more information.
#54
transform-class-properties

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

No branches or pull requests

4 participants