createSynchronizable
Available from 0.6.0
Creates a new Synchronizable holding the provided initial value. Returns the created Synchronizable.
By default it creates a Synchronizable Dynamic.
You can pass a config option to create Synchronizable Fixed instead.
Reference
import { createSynchronizable } from 'react-native-worklets';
const synchronizable = createSynchronizable({ a: 42 });
const counter = createSynchronizable(0, { fixedType: true });


Type definitions
function createSynchronizable<TValue extends number | boolean>(
initialValue: TValue,
config: SynchronizableConfig & { fixedType: true }
): FixedSynchronizable<TValue extends boolean ? boolean : number>;
function createSynchronizable<TValue>(
initialValue: TValue,
config?: SynchronizableConfig
): Synchronizable<TValue>;
type SynchronizableConfig = {
fixedType?: boolean;
};
Arguments
initialValue
The initial value to be held by the created Synchronizable. As it has to be serialized before passing to C++, it must be one of the supported types listed in the Serializable documentation.
With the fixedType option it isn't serialized and must be a number or a boolean.
config
Available from 0.13.0
Optional configuration for the Synchronizable. An object with the following properties:
fixedType- whentrue, the created Synchronizable Fixed stores itsnumberorbooleanvalue directly in native memory, without serialization, and exposes the additionalsetDirtymethod. Defaults tofalse.
Remarks
- In Legacy Eval Mode,
createSynchronizablecan be called only on the RN Runtime. In Bundle Mode, it can be called on any Runtime.