@hzab/data-model 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/hooks.js +14 -3
package/package.json
CHANGED
package/src/hooks.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
|
+
import { merge } from "lodash";
|
|
2
3
|
|
|
3
4
|
import DataModel from "./data-model";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* 解决 hooks 重复实例化导致 query 丢失的问题
|
|
8
|
+
* @param {*} params
|
|
9
|
+
* @param {*} effects
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export const useDataModel = function (params = {}, effects = []) {
|
|
13
|
+
const model = useRef(new DataModel(params));
|
|
14
|
+
return useMemo(() => {
|
|
15
|
+
merge(model.current, params);
|
|
16
|
+
return model.current;
|
|
17
|
+
}, effects);
|
|
7
18
|
};
|