PixiJS | React Hooks | 3kB
- React Hooks -
useState
,useEffect
...useTransition
,useSyncExternalStore
- Component-Based - Native JSX/TSX support with full type system
- Focus on Core Logic - Dedicate to core logic while rexie handles tedious drawing routines
- Sync/Concurrent - Choose your update strategy per render
- 3kB Core - No heavyweight runtime or syntax sugar, simplicity first
- Zero Dependencies - Only depends on PixiJS core
- Direct API Access - Full exposure of native PixiJS APIs
- On-Demand Rendering - Independent multi-instance rendering, mountable to any container, disposable anytime
- Renderer Agnostic - Create new renderers with <100 lines of code
- Framework Integration - Built for seamless embedding in React/Vue/etc
- Universal Core - Platform-agnostic core with browser/Canvas/WebGL extensions
alpha
import * as PIXI from 'pixi.js'
import { h, createRoot, createContext } from 'rexie'
const app = new PIXI.Application()
export const AppContext = createContext(app)
async function mount() {
const container = new PIXI.Container()
createRoot(container).render(
<AppContext.Provider value={app}>
<container>
<graphics />
{'app'}
</container>
</AppContext.Provider>,
)
app.stage.addChild(container)
await app.init({ background: '#ffffff', resizeTo: document.body })
document.body.appendChild(app.canvas)
}
mount()
useState
, useReducer
, useEffect
, useLayoutEffect
, useCallback
, useRef
, useMemo
, useContext
, useTransition
, useImperativeHandle
, useSyncExternalStore
<Fragment>
, <Suspense>
createContext
, createRoot
, lazy
, memo
Some APIs that do not significantly increase runtime's weight and align with PixiJS's design philosophy will be prioritized for implementation as soon as possible: useDebugValue
, useDeferredValue
, useId
, <>
, <Profiler>
, <StrictMode>
, act
, cache
, createPortal
, flushSync
, preconnect
, prefetchDNS
Textures will not be automatically destroyed. You need to manually manage their lifecycle.
Corresponds to the constructor's options
. This property is only set during initialization and will not update with any subsequent changes.
<text options={textStyle} width={200} />
// equivalent to
const text = new PIXI.Text(textStyle)
text.width = 200
If there is a need to create thousands or even more ViewContainer
, the performance of virtual DOM will be extremely poor. Compared to react-dom, it is more prone to stack overflow due to the deeper function call chains in PixiJS's API. Although rexie can adopt queue-based updates like Preact, the performance will still be severely degraded. Therefore, it is recommended to use useRef
to obtain a Container
reference and manually addChild
ViewContainer
. When the component unmounts, these ViewContainer
will still be automatically destroyed, so no manual cleanup is required.
Some setters in PixiJS have execution order dependencies. Props with non-positive-integer keys are traversed in creation order, refer to MDN.
// 1. When text is set before width or placed in constructor options, width affect text
<text
options={{
text,
}}
width={width}
/>
<text
text={text}
width={width}
/>
<text
options={{
width,
text,
}}
/>
// 2. When width is set before text, width won't affect text
<text
options={{
width,
}}
text={text}
/>
<text
width={width}
text={text}
/>
<text
width={width}
>{text}</text>