55![ Open Issues] ( https://img.shields.io/github/issues-raw/techempower/react-governor.svg )
66![ Build Status] ( https://travis-ci.org/TechEmpower/react-governor.svg?branch=master )
77
8-
98Use a governor hook to manage state with actions for, and created by, the people.
109
1110Available as an [ npm package] ( https://www.npmjs.com/package/@techempower/react-governor ) .
@@ -22,15 +21,15 @@ build the boilerplate of `actions`, `dispatch`, and `reducer`.
2221const initialState = { count: 1 };
2322
2423const contract = {
25- increment (state ) {
26- return {
27- count: state .count + 1
28- };
24+ increment () {
25+ return () => ( {
26+ count: this . state .count + 1
27+ }) ;
2928 },
30- add (val , state ) {
31- return {
32- count: state .count + val
33- }
29+ add (val ) {
30+ return () => ( {
31+ count: this . state .count + val
32+ });
3433 }
3534}
3635
@@ -48,7 +47,7 @@ export default function Counter() {
4847}
4948```
5049
51- [ Test that this works] ( https://codesandbox.io/s/hopeful-shannon-lz433 )
50+ [ Test that this works] ( https://codesandbox.io/s/focused-borg-4rrsh )
5251
5352This should feel very similar to how ` useReducer ` works with actions and
5453reducers.
@@ -58,8 +57,8 @@ These actions are functions which take in any number of arguments and the
5857current state. These actions are responsible for returning an object that
5958describes what in the state should be mutated.
6059
61- As from our example, the ` increment ` action returns an object describing that
62- the state should be mutated such that ` count ` is ` state.count + 1 ` . Similarly,
60+ As from our example, the ` increment ` action returns a reducer function describing that
61+ the state should be mutated such that ` count ` is ` this. state.count + 1` . Similarly,
6362the ` add ` action returns an object describing that the state should be mutated
64- such that ` count ` is ` state.count + val ` , and notice that when we called ` add `
63+ such that ` count ` is ` this. state.count + val` , and notice that when we called ` add `
6564that we passed it a value to add.
0 commit comments