Skip to content

Commit 6323cfe

Browse files
author
wangyi
committed
## v3.7.1 2021-08-26
* [bug] fix the problem about when using `react-refresh`, the state can not be connected.
1 parent 9f6195c commit 6323cfe

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

docs/changes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@
3030

3131
## v3.7.0 2021-08-25
3232

33-
* [bug] fix the problem about when using `react-dev-tool`, the state can not be changed.
33+
* [bug] fix the problem about when using `react-dev-tool`, the state can not be changed.
34+
35+
## v3.7.1 2021-08-26
36+
37+
* [bug] fix the problem about when using `react-refresh`, the state can not be connected.

docs/zh/changes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@
3030

3131
## v3.7.0 2021-08-25
3232

33-
* [bug] 修复关于使用 `react-dev-tool` 时,state 无法改变的问题。
33+
* [bug] 修复关于使用 `react-dev-tool` 时,state 无法改变的问题。
34+
35+
## v3.7.1 2021-08-26
36+
37+
* [bug] 修复关于使用 `react-refresh` 热更新时,state 无法链接的问题。

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "use-agent-reducer",
3-
"version": "3.7.0",
3+
"version": "3.7.1",
44
"main": "./index.js",
55
"author": "Jimmy.Harding",
66
"description": "the purpose of this project is make useReducer classify",
@@ -40,10 +40,10 @@
4040
"peerDependencies": {
4141
"react": ">=16.8.0",
4242
"react-dom": ">=16.8.0",
43-
"agent-reducer": "^3.6.0"
43+
"agent-reducer": ">=3.7.2"
4444
},
4545
"dependencies": {
46-
"agent-reducer": "3.7.0"
46+
"agent-reducer": "3.7.2"
4747
},
4848
"devDependencies": {
4949
"@babel/cli": "^7.13.16",

src/index.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export function useAgentReducer<T extends OriginAgent<S>, S>(
8888

8989
useEffect(
9090
() => {
91+
if (reducer && reducer.env.expired) {
92+
reducer.reconnect();
93+
}
9194
reducer.update(state, dispatch);
9295
if (reducer.agent.state !== state) {
9396
dispatch({ type: DefaultActionType.DX_MUTE_STATE, args: reducer.agent.state });
@@ -156,6 +159,9 @@ export function useAgentSelector<T extends OriginAgent<S>, S, R>(
156159

157160
useEffect(
158161
() => {
162+
if (reducer && reducer.env.expired) {
163+
reducer.reconnect();
164+
}
159165
weakDispatch({ type: DefaultActionType.DX_MUTE_STATE, args: reducer.agent.state });
160166
return () => {
161167
const { current: red } = reducerRef;
@@ -198,16 +204,21 @@ export function useAgentMethods<T extends OriginAgent<S>, S>(
198204
const { current: reducer } = reducerRef;
199205

200206
useEffect(
201-
() => () => {
202-
const { current: red } = reducerRef;
203-
if (!red) {
204-
return;
205-
}
206-
red.env.expired = true;
207-
if (!red.destroy) {
208-
return;
207+
() => {
208+
if (reducer && reducer.env.expired) {
209+
reducer.reconnect();
209210
}
210-
red.destroy();
211+
return () => {
212+
const { current: red } = reducerRef;
213+
if (!red) {
214+
return;
215+
}
216+
red.env.expired = true;
217+
if (!red.destroy) {
218+
return;
219+
}
220+
red.destroy();
221+
};
211222
},
212223
[],
213224
);

0 commit comments

Comments
 (0)