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
{{ message }}
This repository was archived by the owner on Apr 3, 2024. It is now read-only.
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:
The 2nd argument to `useEffectReducer(state, initialState)` can either be a static `initialState` or a function that takes in an effect `exec` function and returns the `initialState`:
The `exec(effect)` function returns an **effect entity**, which is a special object that represents the running effect. These objects can be stored directly in the reducer's state:
The 2nd argument to `useEffectReducer(...)` can either be a static `initialState` or a function that takes in `exec` and returns an `initialState` (with executed initial effects). See [Initial Effects](#initial-effects) for more information.
390
+
391
+
```js
392
+
constSomeComponent= () => {
393
+
const [state, dispatch] =useEffectReducer(
394
+
someEffectReducer,
395
+
exec=> {
396
+
exec({ type:'someEffect' });
397
+
return someInitialState;
398
+
},
399
+
{
400
+
someEffect(state, effect) {
401
+
// ...
402
+
},
403
+
}
404
+
);
405
+
406
+
// ...
407
+
};
408
+
```
409
+
351
410
Additionally, the `useEffectReducer` hook takes a 3rd argument, which is the implementation details for [named effects](#named-effects):
0 commit comments