React-Zdog is a declarative React Fiber renderer for Zdog, a 'cute pseudo 3D engine'. It enables developers to integrate Zdog scenes directly into their React applications, leveraging React's component model for building reusable 3D elements with reactive state semantics. The library abstracts Zdog's imperative API into a set of declarative React components like `Illustration` and `Shape`, and provides hooks such as `useRender`, `useZdog`, and `useInvalidate` for finer-grained control over the Zdog instance and its rendering lifecycle. The current stable version is 1.2.2. While there isn't an explicit release cadence, it tends to update in response to changes in React or Zdog. Its key differentiator is simplifying Zdog development for React users, offering a more intuitive and component-based approach compared to direct Zdog API manipulation.
npm install react-zdogVerified import paths — ran on the pinned version, not inferred.
Demonstrates rendering a basic blue Zdog shape within a full-viewport React application using the Illustration component.
Ensure all `react-zdog` hooks are direct or indirect children of an `<Illustration>` component.
Set `<Illustration frameloop='demand' />` when using `useInvalidate()` for explicit render control. Otherwise, allow `frameloop='always'` for continuous rendering.
Add `pointerEvents={true}` to your `<Illustration>` component to enable event listeners on child Zdog elements.Ensure the ref is correctly attached to a `react-zdog` component and the component is mounted before attempting to access its properties. Use optional chaining (`ref.current?.rotate?.y`) or conditional checks (`if (ref.current)`) for safety.
Relocate the hook call to be directly within a functional React component that is rendered as a child of an `<Illustration>` component, or within a custom hook that respects React's rules of hooks.
After directly modifying Zdog object properties when `frameloop='demand'`, call the `invalidate()` function obtained from `useInvalidate()` to force a re-render of the scene.