Skip to content

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

Closed

Description

@petrbrzek

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)
    };
  }
}

Activity

  1. cpojer commented on Aug 31, 2016

    @cpojer
    Member

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

    cc @keyanzhang

  2. keyz commented on Aug 31, 2016

    @keyz
    Contributor

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

  3. Misterhex commented on Jun 6, 2017

    @Misterhex

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions