@rpcbase/client 0.120.0 → 0.121.0

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/helpers/useRPC.js CHANGED
@@ -1,16 +1,21 @@
1
1
  /* @flow */
2
- import {useState, useEffect} from "react"
2
+ import {useCallback, useMemo, useState, useEffect} from "react"
3
3
 
4
- const useRPC = (fn, payload = {}) => {
4
+ const useRPC = (fn, payload) => {
5
5
  const [loading, setLoading] = useState(true)
6
6
  const [error, setError] = useState()
7
7
  const [data, setData] = useState()
8
8
 
9
+ const memoFn = useCallback(fn, [fn])
10
+ const memoPayload = useMemo(() => {
11
+ return payload || {}
12
+ }, [payload])
13
+
9
14
  useEffect(() => {
10
15
  const load = async() => {
11
16
  setLoading(true)
12
17
 
13
- const res = await fn(payload)
18
+ const res = await memoFn(memoPayload)
14
19
 
15
20
  setLoading(false)
16
21
  setData(res)
@@ -19,7 +24,7 @@ const useRPC = (fn, payload = {}) => {
19
24
  }
20
25
  }
21
26
  load()
22
- }, [fn, payload])
27
+ }, [memoFn, memoPayload])
23
28
 
24
29
  return {loading, error, data}
25
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.120.0",
3
+ "version": "0.121.0",
4
4
  "scripts": {
5
5
  "build-firebase": "webpack -c firebase/webpack.config.js",
6
6
  "build": "yarn build-firebase",