@faasjs/react 1.5.0 → 1.6.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/README.md CHANGED
@@ -70,5 +70,6 @@ const client = FaasReactClient({
70
70
  - [faas](functions/faas.md)
71
71
  - [getClient](functions/getClient.md)
72
72
  - [signal](functions/signal.md)
73
+ - [useConstant](functions/useConstant.md)
73
74
  - [useFaas](functions/useFaas.md)
74
75
  - [useSignalState](functions/useSignalState.md)
package/dist/index.d.mts CHANGED
@@ -8,6 +8,11 @@ import * as _preact_signals_core from '@preact/signals-core';
8
8
  export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
9
9
  export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
10
10
 
11
+ /**
12
+ * Returns a constant value that is created by the given function.
13
+ */
14
+ declare function useConstant<T>(fn: () => T): T;
15
+
11
16
  type FaasReactClientInstance = {
12
17
  id: string
13
18
  faas: <PathOrData extends FaasAction>(
@@ -212,4 +217,4 @@ declare function signal<T = any>(initialValue: any, options?: SignalOptions): _p
212
217
  */
213
218
  declare function useSignalState<T = any>(initialValue: T, options?: SignalOptions): readonly [T, (changes: SetStateAction<T>) => void];
214
219
 
215
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions, useSignalState };
220
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useConstant, useFaas, type useFaasOptions, useSignalState };
package/dist/index.d.ts CHANGED
@@ -8,6 +8,11 @@ import * as _preact_signals_core from '@preact/signals-core';
8
8
  export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
9
9
  export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
10
10
 
11
+ /**
12
+ * Returns a constant value that is created by the given function.
13
+ */
14
+ declare function useConstant<T>(fn: () => T): T;
15
+
11
16
  type FaasReactClientInstance = {
12
17
  id: string
13
18
  faas: <PathOrData extends FaasAction>(
@@ -212,4 +217,4 @@ declare function signal<T = any>(initialValue: any, options?: SignalOptions): _p
212
217
  */
213
218
  declare function useSignalState<T = any>(initialValue: T, options?: SignalOptions): readonly [T, (changes: SetStateAction<T>) => void];
214
219
 
215
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions, useSignalState };
220
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useConstant, useFaas, type useFaasOptions, useSignalState };
package/dist/index.js CHANGED
@@ -6,7 +6,14 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var signalsReact = require('@preact/signals-react');
7
7
  var runtime = require('@preact/signals-react/runtime');
8
8
 
9
- // src/client.tsx
9
+ // src/constant.ts
10
+ function useConstant(fn) {
11
+ const ref = react.useRef();
12
+ if (!ref.current) {
13
+ ref.current = { v: fn() };
14
+ }
15
+ return ref.current.v;
16
+ }
10
17
  var clients = {};
11
18
  function FaasReactClient({
12
19
  domain,
@@ -271,5 +278,6 @@ exports.FaasReactClient = FaasReactClient;
271
278
  exports.faas = faas;
272
279
  exports.getClient = getClient;
273
280
  exports.signal = signal;
281
+ exports.useConstant = useConstant;
274
282
  exports.useFaas = useFaas;
275
283
  exports.useSignalState = useSignalState;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, cloneElement, Component } from 'react';
1
+ import { useRef, useState, useEffect, cloneElement, Component } from 'react';
2
2
  import { FaasBrowserClient } from '@faasjs/browser';
3
3
  import { jsx, jsxs } from 'react/jsx-runtime';
4
4
  import { signal as signal$1, effect } from '@preact/signals-react';
@@ -6,7 +6,14 @@ export { batch, computed, effect, signal as originSignal } from '@preact/signals
6
6
  import { useSignal, useSignalEffect } from '@preact/signals-react/runtime';
7
7
  export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
8
8
 
9
- // src/client.tsx
9
+ // src/constant.ts
10
+ function useConstant(fn) {
11
+ const ref = useRef();
12
+ if (!ref.current) {
13
+ ref.current = { v: fn() };
14
+ }
15
+ return ref.current.v;
16
+ }
10
17
  var clients = {};
11
18
  function FaasReactClient({
12
19
  domain,
@@ -233,4 +240,4 @@ function useSignalState(initialValue, options = {}) {
233
240
  ];
234
241
  }
235
242
 
236
- export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, signal, useFaas, useSignalState };
243
+ export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, signal, useConstant, useFaas, useSignalState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@faasjs/browser": "1.5.0"
25
+ "@faasjs/browser": "1.6.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "*",