wix-incubator / vscode-glean

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

Conversion: a stateful component -> a component connected to Redux #67

Open VytautasT opened 5 years ago

borislit commented 5 years ago

Hey @VytautasT. Can you elaborate/provide example?

2012mjm commented 5 years ago
import { connect } from 'react-redux';

class Counter extends Component = () => {
  return <div>{this.props.counter}</div>
}

function mapStateToProps(state) {
  return {
    counter: state.counter
  }
}

export default connect(mapStateToProps)(Counter)

with Hooks

import { useSelector } from 'react-redux';

export const Counter = () => {
  const counter = useSelector(state => state.counter);
  return <div>{counter}</div>
}
borislit commented 5 years ago

Interesting @2012mjm. It should be quiet easy to add it. The only concern I have - should this be a separate extension or not? I mean, identifying usage of a certain library can be quiet difficult. WDYT?