@bluelibs/smart
v2.2.1
Published
Smart is a very small library which helps decouple state management and non-ui-related actions to separate classes.
Downloads
594
Readme
Smart is a simple tool which allows you to decouple state and logic from your components.
Goodies:
- ✅ Uses React Hooks behind the scenes
- ✅ Manage state and actions separately from your components
- ✅ TypeScript auto-completion at every step
- ✅ Ultra light-weight
- ✅ Integration with Redux DevTools
Install
npm install --save @bluelibs/smart
import { Smart, smart } from "@bluelibs/smart";
// This is where you make api queries and this is where you set or update the state
class Counter extends Smart {
state = {
count: 0,
};
increment() {
this.setState({ count: this.state.count + 1 });
}
}
// Components just call the Counter and use `counter.state`
function Component() {
const counter = useSmart(Counter);
// Access to api.state
// Ability to trigger api.increment()
}
smart(Counter)(Component);
Documentation
Click here to go to the documentation
Support
This package is part of BlueLibs family. If you enjoy this work please show your support by starring the main package. If not, let us know what can we do to deserve it, our feedback form is here