@faasjs/react 6.0.0 → 6.2.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);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "6.0.0",
3
+ "version": "6.2.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.0.0"
33
+ "@faasjs/browser": "6.2.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@faasjs/browser": "6.0.0",
36
+ "@faasjs/browser": "6.2.0",
37
37
  "@types/react": "*",
38
38
  "react": "*"
39
39
  },