reason-react-update
Advanced tools
Comparing version 0.1.1 to 1.0.0
@@ -0,1 +1,8 @@ | ||
## 1.0.0 | ||
Features: | ||
- Add `ReactUpdateLegacy` for uncancellable effects, easing the migration process if copy pasting from record API reducers (c4ccec5) | ||
- Add `useReducerWithMapState` API to enable lazy state init (19eee9a) | ||
## 0.1.1 | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "reason-react-update", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"scripts": { | ||
@@ -26,3 +26,3 @@ "build": "bsb -make-world", | ||
"devDependencies": { | ||
"bs-platform": "^5.0.1", | ||
"bs-platform": "^5.0.3", | ||
"react": "^16.8.0", | ||
@@ -29,0 +29,0 @@ "react-dom": "^16.8.0", |
@@ -34,3 +34,3 @@ # reason-react-update | ||
| Increment => Update(state + 1) | ||
| Decrement => Update(state + 1) | ||
| Decrement => Update(state - 1) | ||
} | ||
@@ -46,2 +46,34 @@ ); | ||
### Lazy initialisation | ||
## ReactUpdate.useReducer | ||
If you'd rather initialize state lazily (if there's so computation you don't want executed at every render for instance), use `useReducerWithMapState` where the first argument is a function taking `unit` and returning the initial state. | ||
```reason | ||
type state = int; | ||
type action = | ||
| Increment | ||
| Decrement; | ||
[@react.component] | ||
let make = () => { | ||
let (state, send) = | ||
ReactUpdate.useReducerWithMapState( | ||
() => 0, | ||
(action, state) => | ||
switch (action) { | ||
| Increment => Update(state + 1) | ||
| Decrement => Update(state + 1) | ||
} | ||
); | ||
<div> | ||
{state->Js.String.make->React.string} | ||
<button onClick={_ => send(Decrement)}> "-"->React.string </button> | ||
<button onClick={_ => send(Increment)}> "+"->React.string </button> | ||
</div>; | ||
}; | ||
``` | ||
### Cancelling a side effect | ||
@@ -66,1 +98,3 @@ | ||
``` | ||
If you want to copy/paste old reducers that don't support cancellation, you can use `ReactUpdateLegacy` instead in place of `ReactUpdate`. Its `SideEffects` and `UpdateWithSideEffects` functions accept functions that return `unit`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11707
12
1
98