wix-incubator / vscode-glean

The extension provides refactoring tools for your React codebase
MIT License
1.46k stars 56 forks source link

Adds state class property support to the stateful-to-stateless transform #85

Closed aeciorc closed 4 years ago

aeciorc commented 4 years ago

I've noticed that when the state is initialized as a class property (rather than in the constructor), it's ignored by stateful-to-stateless. For example:

class Foo extends React.Component {
  state = {
    vixe: 1,
    oxe: "bla"
  };

  render() {

  }
}

becomes

const Foo = props => {};

instead of

const Foo = props => {
  const [vixe, setVixe] = useState(1);
  const [oxe, setOxe] = useState("bla");
};

This PR adds a simple fix