compax v1.0.79
Compax 🤏🏻
State management tool for quick & easy usage.
Usage
import * as compax from 'compax';Initial State
Generate a new store object using the store method:
const initState = {
counter: 0,
};
const store = compax.store(initState);Configure deafult setters for state members:
const store = compax.store(initState, {
counter: val => val + 1,
});Store Methods
value
Get the state value using the value method:
const state = store.value();patch
Set the state value using the patch method:
store.patch({counter: 1});Pass a function to get the previous state:
store.patch(prev => ({counter: prev.counter + 1}));reset
Reset the state to initial value using the reset method:
store.reset();Pass a dependencies array to reset selective members of the state:
store.reset(['counter']);merge
Merge component's props with state members using the merge method:
export default store.merge(Component);HOC listening to state changes and updating the props
fetch
Get updated state value inside a functional component using the fetch method:
const {counter} = store.fetch();Hook listening to state changes and returns the updated state value
Named by Chat-GPT 🤖
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago