@faasjs/react 6.1.0 → 6.3.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/dist/index.cjs CHANGED
@@ -90,10 +90,13 @@ function useSplittingState(initialStates) {
90
90
  }
91
91
  function createSplittingContext(defaultValue) {
92
92
  const keys = Array.isArray(defaultValue) ? defaultValue : Object.keys(defaultValue);
93
- const defaultValues = Array.isArray(defaultValue) ? keys.reduce((prev, cur) => {
94
- prev[cur] = null;
95
- return prev;
96
- }, {}) : defaultValue;
93
+ const defaultValues = Array.isArray(defaultValue) ? keys.reduce(
94
+ (prev, cur) => {
95
+ prev[cur] = null;
96
+ return prev;
97
+ },
98
+ {}
99
+ ) : defaultValue;
97
100
  const contexts = {};
98
101
  for (const key of keys) contexts[key] = react.createContext(defaultValues[key]);
99
102
  function Provider(props) {
@@ -116,7 +119,12 @@ function createSplittingContext(defaultValue) {
116
119
  const obj = /* @__PURE__ */ Object.create(null);
117
120
  for (const key of Object.keys(contexts)) {
118
121
  Object.defineProperty(obj, key, {
119
- get: () => react.useContext(contexts[key])
122
+ get: () => {
123
+ if (!contexts[key]) {
124
+ throw new Error(`Context for key "${key}" is undefined`);
125
+ }
126
+ return react.useContext(contexts[key]);
127
+ }
120
128
  });
121
129
  }
122
130
  return Object.freeze(obj);
@@ -154,7 +162,7 @@ function FaasDataWrapper(props) {
154
162
  );
155
163
  const [loaded, setLoaded] = react.useState(false);
156
164
  react.useEffect(() => {
157
- if (!loaded && !request.loading) setLoaded(true);
165
+ if (!request.loading) setLoaded((prev) => prev === false ? true : prev);
158
166
  }, [request.loading]);
159
167
  useEqualEffect(() => {
160
168
  if (props.onDataChange) props.onDataChange(request);
@@ -497,7 +505,7 @@ function FormFooter() {
497
505
  }, [setSubmitting, setErrors, rules, items, lang, onSubmit]);
498
506
  const MemoizedButton = react.useMemo(
499
507
  () => /* @__PURE__ */ jsxRuntime.jsx(Elements.Button, { submitting, submit: handleSubmit, children: lang.submit }),
500
- [submitting, handleSubmit, lang.submit]
508
+ [submitting, handleSubmit, lang.submit, Elements.Button]
501
509
  );
502
510
  return MemoizedButton;
503
511
  }
package/dist/index.d.ts CHANGED
@@ -326,7 +326,7 @@ type FaasReactClientInstance = {
326
326
  faas: <PathOrData extends FaasAction>(action: PathOrData | string, params: FaasParams<PathOrData>, options?: Options) => Promise<Response<FaasData<PathOrData>>>;
327
327
  useFaas: <PathOrData extends FaasAction>(action: PathOrData | string, defaultParams: FaasParams<PathOrData>, options?: useFaasOptions<PathOrData>) => FaasDataInjection<PathOrData>;
328
328
  FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
329
- onError: OnError;
329
+ onError?: OnError;
330
330
  browserClient: FaasBrowserClient;
331
331
  };
332
332
  /**
package/dist/index.mjs CHANGED
@@ -88,10 +88,13 @@ function useSplittingState(initialStates) {
88
88
  }
89
89
  function createSplittingContext(defaultValue) {
90
90
  const keys = Array.isArray(defaultValue) ? defaultValue : Object.keys(defaultValue);
91
- const defaultValues = Array.isArray(defaultValue) ? keys.reduce((prev, cur) => {
92
- prev[cur] = null;
93
- return prev;
94
- }, {}) : defaultValue;
91
+ const defaultValues = Array.isArray(defaultValue) ? keys.reduce(
92
+ (prev, cur) => {
93
+ prev[cur] = null;
94
+ return prev;
95
+ },
96
+ {}
97
+ ) : defaultValue;
95
98
  const contexts = {};
96
99
  for (const key of keys) contexts[key] = createContext(defaultValues[key]);
97
100
  function Provider(props) {
@@ -114,7 +117,12 @@ function createSplittingContext(defaultValue) {
114
117
  const obj = /* @__PURE__ */ Object.create(null);
115
118
  for (const key of Object.keys(contexts)) {
116
119
  Object.defineProperty(obj, key, {
117
- get: () => useContext(contexts[key])
120
+ get: () => {
121
+ if (!contexts[key]) {
122
+ throw new Error(`Context for key "${key}" is undefined`);
123
+ }
124
+ return useContext(contexts[key]);
125
+ }
118
126
  });
119
127
  }
120
128
  return Object.freeze(obj);
@@ -152,7 +160,7 @@ function FaasDataWrapper(props) {
152
160
  );
153
161
  const [loaded, setLoaded] = useState(false);
154
162
  useEffect(() => {
155
- if (!loaded && !request.loading) setLoaded(true);
163
+ if (!request.loading) setLoaded((prev) => prev === false ? true : prev);
156
164
  }, [request.loading]);
157
165
  useEqualEffect(() => {
158
166
  if (props.onDataChange) props.onDataChange(request);
@@ -495,7 +503,7 @@ function FormFooter() {
495
503
  }, [setSubmitting, setErrors, rules, items, lang, onSubmit]);
496
504
  const MemoizedButton = useMemo(
497
505
  () => /* @__PURE__ */ jsx(Elements.Button, { submitting, submit: handleSubmit, children: lang.submit }),
498
- [submitting, handleSubmit, lang.submit]
506
+ [submitting, handleSubmit, lang.submit, Elements.Button]
499
507
  );
500
508
  return MemoizedButton;
501
509
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "6.1.0",
3
+ "version": "6.3.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -30,10 +30,10 @@
30
30
  "dist"
31
31
  ],
32
32
  "peerDependencies": {
33
- "@faasjs/browser": "6.1.0"
33
+ "@faasjs/browser": "6.3.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@faasjs/browser": "6.1.0",
36
+ "@faasjs/browser": "6.3.0",
37
37
  "@types/react": "*",
38
38
  "react": "*"
39
39
  },