2.0.4 • Published 5 years ago
@dwalter/spider-hook v2.0.4
@dwalter/spider-hook
State management for React that just works.
spider-hook
replaces redux
, react-redux
, redux-thunk
, and reselect
without all the bloat.
spider-hook
and its 2 dependencies are smaller thanreact-redux
is alone.spider-hook
exports only 8 members, and only half of those are frequently used.spider-hook
is made to play nice with all your favorite tools includingtypescript
,prettier
,eslint
/tslint
,vscode
, andwebpack
/rollup
.spider-hook
performs similarly to aggressively usedreselect
.
Under the hood, spider-hook
uses @dwalter/spider-store
to do the heavy lifting. This has one extra benefit: spider-hook
automatically and safely handles state stores split up across multiple bundles. Your state will be unaffected by load order.
// state reducer function
function counterReducer(state = 0, action) {
switch (action.type) {
case 'increment': {
return state + 1
}
default: {
return state
}
}
}
// action creator
// (note the reducers prop on the action)
function increment() {
return {
type: 'increment',
reducers: [counterReducer],
}
}
// boilerplate in App component
function App() {
return (
<SpiderRoot>
<Counter />
</SpiderRoot>
)
}
// component consuming state
function Counter() {
const count = useSelector(counterReducer)
const actions = useActions({ increment })
return <div onClick={actions.increment}>{count}</div>
}
Exports
Other Concepts
2.0.4
5 years ago
2.0.3
5 years ago
1.7.0
5 years ago
1.6.0
5 years ago
1.5.2
5 years ago
1.5.1
5 years ago
1.5.0
5 years ago
1.4.6
5 years ago
1.4.5
5 years ago
1.4.4
5 years ago
1.4.3
5 years ago
1.4.2
5 years ago
1.4.1
5 years ago
1.4.0
5 years ago
1.3.4
5 years ago
1.3.3
5 years ago
1.3.2
5 years ago
1.3.1
5 years ago
1.3.0
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago