Home > @pago/reactive

reactive package

Classes

Class Description
SubscriptionController Manages the subscription to tracked references and objects within a memoized function.

Functions

Function Description
derived(fn) Returns a ReadonlyRef whose value will always point to the latest result of the given function. The function will only be executed once per set of values.
effect(fn) Sometimes your components will need to initiate side effects to start fetching data, etc. This function enables you to implement that behaviour. The provided effect will be observed and will run automatically whenever any of its tracked values change. It will automatically be invalidated when the component is unmounted.The function passed into effect will behave similarly to one that is passed to Reacts useEffect in that it won’t be executed during server side rendering.
fromHook(fn) The function passed to fromHook will always be executed when rendering the component.
inject(context) Injects a React.Context into a Reactive Function Component.
memoize(fn, controller) Returns a function that is only executed again if any of its tracked values have changed. The controller can be used to establish a notification system and is largely irrelevant to end users of the API.
r(render) This function is a pure type-cast to avoid TypeScript from complaining when using a Reactive Function Component without wrap().
reactive(initialValue) Transforms an object into a tracked version. Changing the object returned from reactive will also change the original. All watchers and derived values will update. Access to Object.keys as well as checking for the existance of a key through the in operator will also be tracked.
readonly(ref) Converts a mutable Ref to a ReadonlyRef.
ref(initialValue) Creates a new tracked reference value.
toRef(store, prop) Extracts a single property from a tracked object into a RefObject.
toRefs(store) Converts a tracked object into an object of Ref instances.
useRefValue(ref) Returns the current value of a RefObject and starts to track its value once the component has been mounted.An update will be scheduled if the value of the reference has changed between the first render of the component and mounting it.
watchEffect(fn) Executes the given effect immediately and tracks any used values. When any of them change, it will execute the effect again. If a teardown function has been registered through the onInvalidate param, it will be executed before the effect is executed again, allowing for cleanup.
wrap(construct) Converts a Reactive Function Component into a React Function Component. A Reactive Function Component returns a render function which is automatically tracked. If none of its input values have changed, the render function will not execute during consequitive renderings of the component. Instead, the old virtual DOM tree will be returned, enabling frameworks like React and Preact to bail out of rendering early on.It is usually a better developer experience to configure your Build tool to use @pago/reactive as the @jsxImportSource or the @jsxFactory.

Interfaces

Interface Description
Effect A function that represents a pure side effect with no input and no output.
ReadonlyRef A tracked reference to a value that can’t be modified.
Ref A tracked reference to a value. Reading it from it should mark it as “read” in the current scope, writing to it should mark it as dirty.When a Ref is marked as dirty, any watcher or derivative will eventually be updated to its new value.Note that it is not possible to read and update a ref within the same tracked scope.
RefObject An Ref object that supports reading & writing in the same tracked scope by providing a specific RefObject.update() method.

Variables

Variable Description
createElement An interceptor for the standard React createElement function from the react package.
jsx An interceptor for the standard React jsx function from the react/jsx-runtime package.
jsxs An interceptor for the standard React jsxs function from the react/jsx-runtime package.

Type Aliases

Type Alias Description
RefContainer An object with only RefObject values.
Store An object that inlines all Ref values and enables using them transparently.