With the React hooks the React.Component
will be deprecated soon ⚰️.
Not only this new hook all-functional API is disgusting 🤢, it also forces us to rewrite our apps, which takes greater than zero hours 💰. This project allows you to write your react components in the old-fasioned way, as you love ❤️ and are used to do. No need to learn new react, which will be deprecated in a year anyway.
npm install react-hook-component
import React from "react";
import createComponent from "react-hook-component";
// Our component definition looks like in the good old days 🤩
const Counter = createComponent({
getInitialState() {
return {
count: 0
};
},
handleIncrement() {
this.setState({
count: this.state.count + 1
});
},
handleDecrement() {
this.setState({
count: this.state.count - 1
});
},
render() {
const { count } = this.state;
return (
<div>
<span>{count}</span>
<button onClick={this.handleIncrement}>+</button>
<button onClick={this.handleDecrement}>-</button>
</div>
);
}
});
See test.js
- implement getDefaultProps
- implement forceUpdate
- tests for state, props
- test shouldComponentUpdate when enzyme ready
Feel free to open PR if you want to help!