Skip to content

Function: useBoundProp()

API / @xmachines/play-solid / useBoundProp

function useBoundProp<T>(propValue, bindingPath): [T | undefined, (value) => void];

Defined in: @json-render/solid

Hook for two-way bound props. Returns [value, setValue] where:

  • value is the already-resolved prop value (passed through from render props)
  • setValue writes back to the bound state path (no-op if not bound)

Designed to work with the bindings map that the renderer provides when a prop uses { $bindState: "/path" } or { $bindItem: "field" }.

Type Parameters

Type Parameter
T

Parameters

ParameterType
propValueT | undefined
bindingPathstring | undefined

Returns

[T | undefined, (value) => void]

Example

import { useBoundProp } from "@json-render/solid";
const Input: ComponentRenderer = (ctx) => {
const [value, setValue] = useBoundProp<string>(ctx.props.value, ctx.bindings?.value);
return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
};