🦅 Custom React hook; drop-in replacement for this.setState
MIT License
use-legacy-state
This package provides a custom React Hook that behaves the same way as this.setState
from React component classes, which may help you transition a component from a class to a function when you want to use hooks in that component.
setState
this.setState
null
this.setState
)$ npm install --save use-legacy-state
const useLegacyState = require("use-legacy-state");
function Counter(props) {
const [state, setState] = useLegacyState({ count: 0 });
return (
<div>
Count: {state.count}
<button onClick={() => setState({ count: state.count + 1 })}>
Increase
</button>
</div>
);
}
MIT