Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 1507545

Browse files
authored
Merge pull request #11 from davidkpiano/davidkpiano/initial-effects
2 parents 8c75e99 + 8238477 commit 1507545

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

.changeset/three-chefs-play.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# use-effect-reducer
22

3+
## 0.6.0
4+
5+
### Minor Changes
6+
7+
- b1c53b2: Added support for initial effects, via the 2nd argument to `useEffectReducer`, which can either be a static `initialState` or a function that takes in `exec` and returns an initial state as well as executing initial effects:
8+
9+
```js
10+
const fetchReducer = (state, event) => {
11+
if (event.type === 'RESOLVE') {
12+
return {
13+
...state,
14+
data: event.data,
15+
};
16+
}
17+
18+
return state;
19+
};
20+
21+
const getInitialState = exec => {
22+
exec({ type: 'fetchData', someQuery: '*' });
23+
24+
return { data: null };
25+
};
26+
27+
// (in the component)
28+
const [state, dispatch] = useEffectReducer(fetchReducer, getInitialState, {
29+
fetchData(_, { someQuery }) {
30+
fetch(`/some/api?${someQuery}`)
31+
.then(res => res.json())
32+
.then(data => {
33+
dispatch({
34+
type: 'RESOLVE',
35+
data,
36+
});
37+
});
38+
},
39+
});
40+
```
41+
342
## 0.5.0
443

544
### Minor Changes

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "use-effect-reducer",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -16,7 +16,8 @@
1616
"build": "tsdx build",
1717
"test": "tsdx test --passWithNoTests",
1818
"lint": "tsdx lint",
19-
"prepare": "tsdx build"
19+
"prepare": "tsdx build",
20+
"changeset:publish": "changeset version && changeset publish"
2021
},
2122
"keywords": [
2223
"react",

0 commit comments

Comments
 (0)