You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**That's it!** That's your entire state handler for a couple of functions that can by synchronous or promise-returing! Your react or whatever view can just look in redux for `props.someState.exampleA` or `props.someState.exampleAError`.
196
+
That's your entire state handler for a couple of functions that can by synchronous or promise-returing! Your react or whatever view can just look in redux for `props.someState.exampleA` or `props.someState.exampleAError`.
197
+
198
+
199
+
## cache
200
+
201
+
Sometimes you only want to do an action once. For example only fetch data from an API if you haven't already. `makeDuck` and `promiseHandler` can take an option to return actions that will check state and only call your action if needed.
202
+
203
+
```javascript
204
+
205
+
constduck=makeDuck({
206
+
exmapleA : somePromiseAPI
207
+
}, {namespace:'foo', cache:true});
208
+
209
+
exportconst { exampleA, exampleACached } = duck;
210
+
exportdefaultduck.reducerCombined;
211
+
212
+
```
213
+
214
+
In this example if you call `exampleACached` the cooldux middleware will check the state for `foo.exampleA` and if it sees a [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) value return that, otherwise call the `exampleA` function. **Your namespace must be the same property this duck belongs to.**
215
+
216
+
217
+
218
+
## That's it for now!
197
219
198
220
Each of the previous examples build on eachother, you certainly don't need to use all of the cooldux functions. It might be that just the early examples feel helpful or it may be that you're on board to use it all and just let the automagic take you.
0 commit comments