A hook to use a value from an haystack-server as react state.
This hook should be used when input flexibility is required.
It is meant to abstract how data is actually retrieved/polled/written, enabling at the same time a data driven approach.
It takes a ResolvableDict that contains the record data and a meta tag that indicates how to interact with that record to poll and write an HVal.
See
ResolvableDict for the options available.
IMPORTANT: this hook requires a ClientContext to work.
const [point] = useReadByFilter('point and temp and zone and sp').grid// One-shot reading the first point that matches the filter
//Adding meta data to the dict (this could be done server side) constresolvableDict1 = point?.newCopy().set('meta', {resolveType:'point'}) asResolvable<HNum> constresolvableDict2 = point?.newCopy().set('meta', {resolveType:'tag', readTag:'precision'}) asResolvable<HNum>
// The actual state used depends on the metadata in the dict: const [pointValue, setPointValue, point] = useResolveHaystackValue<HNum>(resolvableDict1) const [pointPrecision, setPointPrecision, point] = useResolveHaystackValue<HNum>(resolvableDict2)
Returns
a resolved value and a function to update it on the server, if the value is not resolved it is passed through.
A hook to use a value from an haystack-server as react state.
This hook should be used when input flexibility is required. It is meant to abstract how data is actually retrieved/polled/written, enabling at the same time a data driven approach.
It takes a ResolvableDict that contains the record data and a meta tag that indicates how to interact with that record to poll and write an HVal.
See
IMPORTANT: this hook requires a ClientContext to work.
Example
Here’s a usage example:
Returns
a resolved value and a function to update it on the server, if the value is not resolved it is passed through.