API Overview
React Facet provides a complete API for building performant game UIs with observable state management. This overview covers the main APIs you'll use when building with React Facet.
Hooks
React Facet provides a comprehensive set of hooks for working with facets. Most mirror standard React hooks, making them familiar and easy to learn.
Core State & Derivation Hooks
Standard React analogs:
useFacetState- Create local facet state (useStateequivalent)useFacetEffect- React to facet changes (useEffectequivalent)useFacetLayoutEffect- Synchronous facet effects (useLayoutEffectequivalent)useFacetMemo- Cached derived facets (useMemoequivalent)useFacetCallback- Memoized callbacks (useCallbackequivalent)useFacetRef- Ref tracking facet values (useRefequivalent)
Facet-specific hooks:
useFacetMap- Derive facets (lightweight, default choice)useFacetWrap- Convert values or facets to facetsuseFacetWrapMemo- Wrap with stable facet referenceuseFacetUnwrap- ⚠️ Extract plain values (causes re-renders)useFacetTransition- Mark updates as low-priority transitions
Mount Components
Conditional rendering components that work seamlessly with facets and the custom renderer.
Mount- Conditionally mount children based on aFacet<boolean>Map- Render lists from aFacet<Array<T>>With- Render with facet value (scopes re-renders)
When to use: These components are essential for conditional rendering and lists when working with facets, as they prevent unnecessary re-renders by scoping updates.
Learn more about Mount components →
fast-* Components
High-performance DOM elements that accept facets directly as props, bypassing React reconciliation for updates.
Available with @react-facet/dom-fiber:
fast-div- Container elementfast-text- Text content (no wrapper element)fast-input- Text input fieldfast-textarea- Multi-line text inputfast-img- Image elementfast-a- Anchor/link elementfast-span- Inline elementfast-p- Paragraph element
When to use: Use fast-* components when you need to bind facets to DOM properties. For static content or non-facet props, regular HTML elements work fine.
Performance benefit: Updates to facet-bound props bypass React reconciliation, providing near-native DOM performance.
Learn more about fast-components →
Equality Checks
Built-in equality check functions for controlling when facets update.
defaultEqualityCheck- Default (primitives:===, objects/arrays: always different). Performance optimized.strictEqualityCheck- Type-safe strict equality for primitives and functions onlyshallowObjectEqualityCheck- Shallow object comparisonshallowArrayEqualityCheck- Shallow array comparison
When to use: Pass custom equality checks to hooks like useFacetMap and useFacetMemo to prevent unnecessary updates when deriving objects or arrays. For primitives, the default is already optimized.
Learn more about equality checks →
Helpers
Utility functions for working with facets.
multiObserve- Observe multiple facets simultaneouslyhasDefinedValue- Check if a facet has a value (notNO_VALUE)areAllDefinedValues- Check if all facets have values