react
Interfaces
Props
Defined in: react/types.ts:179
Generic dictionary representing a component props object.
Pre-defines common React properties (key, ref, style, styles, children) while
allowing arbitrary custom properties via index signature.
Indexable
[key: string]: anyProperties
| Property | Type | Defined in |
|---|---|---|
key? | Key | react/types.ts:180 |
ref? | Ref<any> | react/types.ts:181 |
style? | string | react/types.ts:182 |
styles? | Record<string, any> | react/types.ts:183 |
children? | ReactNode | react/types.ts:184 |
ReactElement
Defined in: react/types.ts:212
Ephemeral virtual DOM descriptor (snapshot blueprint) created by createElement or <Component />.
Holds props and child elements for the current render pass, then is discarded by the garbage collector.
Type Parameters
| Type Parameter | Default type |
|---|---|
P extends Props | Props |
T extends ElementType<any> | ElementType<any> |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
key? | Key | Optional key for list reconciliation stability. | react/types.ts:214 |
type | T | Element type: native Factorio string tag or functional component. | react/types.ts:216 |
props | P & object | Element props including children. | react/types.ts:218 |
EntityLifecycleCallbacks
Defined in: react/types.ts:231
Lifecycle event handlers for components linked to a specific Factorio in-game entity (useEntityLifecycle).
Automatically handles cases where the bound entity is mined, destroyed, or revived.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
onDestroyed? | (this: void) => void | Called when the bound entity is destroyed, mined, or becomes invalid in the game world. | react/types.ts:233 |
onRevived? | (this: void, newEntity: LuaEntity) => void | Called when the bound entity is revived (e.g. via undo / ghost revival), providing the fresh LuaEntity reference. | react/types.ts:235 |
Fiber
Defined in: react/types.ts:249
Fiber - Serializable state node in our component tree.
Persisted directly into Factorio global storage (storage.reactRoots).
Contains ONLY safe-to-serialize plain data (no functions, no metatables, no C++ references).
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
id | number | Unique sequential ID assigned to this fiber node. | react/types.ts:251 |
type | string | String identifier of the component or native tag name. | react/types.ts:253 |
key? | Key | Optional reconciliation key. | react/types.ts:255 |
hooks | unknown[] | Serialized hook state slots (primitive state, reducer state). | react/types.ts:257 |
children | Fiber[] | Child fiber nodes. | react/types.ts:259 |
TransientState
Defined in: react/types.ts:285
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
fiber? | Fiber | Direct in-memory reference to the corresponding serializable Fiber node. | react/types.ts:287 |
parent? | Fiber | Direct in-memory reference to the parent Fiber node in the component tree. | react/types.ts:289 |
root? | ReactRootData | Direct in-memory reference to the enclosing React root data. | react/types.ts:291 |
props | Props | Latest props snapshot passed to this fiber. | react/types.ts:293 |
elem? | LuaGuiElement | Live C++ Factorio GUI element reference. | react/types.ts:295 |
hooks? | Record<number, HookInstance> | Array of in-memory hook instances keyed by hook slot index (0..N). | react/types.ts:297 |
handlers? | Record<Color<any>, | ((this: void, event: GuiEventData) => void) | undefined> | Fast pre-indexed event handlers table keyed directly by Factorio event ID (O(1) lookup). | react/types.ts:299 |
elementType? | any | Live component function or native tag element type reference in RAM. | react/types.ts:301 |
ReactRootData
Defined in: react/types.ts:307
Root metadata saved in global storage.reactRoots to enable rehydration upon game load.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
id | number | Unique sequential Root ID. | react/types.ts:309 |
containerElem | LuaGuiElement | Native parent container element (e.g. player.gui.screen). | react/types.ts:311 |
fiber? | Fiber | Root fiber tree. | react/types.ts:313 |
rootType | string | Registered string name of the root component function. | react/types.ts:315 |
rootProps? | Props | Initial props passed to the root component. | react/types.ts:317 |
UseWindowOptions
Defined in: react/types.ts:325
Configuration options for the useWindow lifecycle hook.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
autoCenter? | boolean | Automatically centers the window upon opening and disables position persistence. Default: false. | react/types.ts:327 |
pinnable? | boolean | Enables pinning functionality (window stays open when ‘E’/Escape is pressed). Default: false. | react/types.ts:329 |
defaultPinned? | boolean | Initial pinned state if no saved state is found in storage. Default: false. | react/types.ts:331 |
windowKey? | string | Custom unique storage key for saving coordinates and pin state. Default: fiber.type. | react/types.ts:333 |
closeOnEscape? | boolean | Automatically closes window on Escape/‘E’ when not pinned. Default: true. | react/types.ts:335 |
guiTypeFilter? | gui_type | Filter for on_gui_closed event type. Default: defines.gui_type.custom. | react/types.ts:337 |
locationDebounceTicks? | number | Delay in game ticks before saving dragged window position to storage. Default: 30 (0.5s). | react/types.ts:339 |
UseWindowReturn
Defined in: react/types.ts:345
Controller interface returned by the useWindow hook.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
close | (this: void) => void | Programmatically closes and unmounts the window, resetting player.opened and destroying the root. | react/types.ts:347 |
pinned | boolean | Current pinned state of the window. | react/types.ts:349 |
setPinned | Dispatch<SetStateAction<boolean>> | State setter for pinned. Automatically persists changes to storage.reactWindowPinned. | react/types.ts:351 |
togglePin | (this: void) => void | Helper that toggles the pinned state (setPinned(prev => !prev)). | react/types.ts:353 |
onLocationChanged? | (this: void, ev: OnGuiLocationChangedEvent) => void | Event handler to pass to onLocationChanged prop to save window coordinates on drag. | react/types.ts:355 |
ObserverData
Defined in: react/types.ts:367
Internal tracking record for an entity lifecycle observer (useEntityLifecycle).
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
entity | LuaEntity | Live Factorio entity reference. | react/types.ts:369 |
unit_number? | UnitNumber | Entity unit number if supported. | react/types.ts:371 |
surface_index | SurfaceIndex | Surface index where the entity was placed. | react/types.ts:373 |
position | MapPosition | Map coordinates of the entity. | react/types.ts:375 |
callbacks | EntityLifecycleCallbacks | Lifecycle callbacks to trigger on death/mining/revival. | react/types.ts:377 |
PendingEffect
Defined in: react/types.ts:383
Internal descriptor for a deferred side-effect queued during component render.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
fiberId | number | Unique ID of the component Fiber node. | react/types.ts:385 |
hookIndex | number | Sequential hook slot index within the component. | react/types.ts:387 |
effect | EffectCallback | Side-effect callback to execute in the commit phase. | react/types.ts:389 |
DebounceState
Defined in: react/types.ts:395
Internal state tracking an active debounced task in the scheduler.
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
taskId? | number | Scheduler task ID if a timeout is currently pending. | react/types.ts:397 |
targetTick? | number | Target game tick when callback should be executed. | react/types.ts:399 |
callback | (this: void, …args: any[]) => void | Current callback closure to execute upon timer expiry. | react/types.ts:401 |
Type Aliases
GuiElementFor
type GuiElementFor<T> = Extract<Color, { type: T;}>;Defined in: react/types.ts:46
Automatically extracts the concrete live LuaGuiElement subtype for element type T.
Example: GuiElementFor<"button"> resolves to ButtonGuiElement.
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends Color | Color |
Ref
type Ref<T> = RefObject<T> | RefCallback<T>;Defined in: react/types.ts:55
Universal ref type: either a mutable { current } object container or a callback function.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | Color |
NonFunction
type NonFunction<T> = T extends (this: void, ...args: any[]) => any ? never : T;Defined in: react/types.ts:61
Utility type restricting state values to serializable non-functional types.
Functions cannot be saved in persistent Factorio storage and should be managed via useCallback or useRef.
Type Parameters
| Type Parameter |
|---|
T |
SetStateAction
type SetStateAction<T> = T | ((this: void, prev: T) => T);Defined in: react/types.ts:64
A value or a functional state updater callback.
Type Parameters
| Type Parameter |
|---|
T |
Dispatch
type Dispatch<A> = (this: void, value: A) => void;Defined in: react/types.ts:67
A function that updates state (e.g. from useState or useReducer).
Type Parameters
| Type Parameter |
|---|
A |
Parameters
| Parameter | Type |
|---|---|
this | void |
value | A |
Returns
void
EffectCleanup
type EffectCleanup = (this: void) => void;Defined in: react/types.ts:70
An optional cleanup callback returned by a side-effect.
Parameters
| Parameter | Type |
|---|---|
this | void |
Returns
void
EffectCallback
type EffectCallback = (this: void) => void | EffectCleanup;Defined in: react/types.ts:73
A side-effect callback function passed to useEffect.
Parameters
| Parameter | Type |
|---|---|
this | void |
Returns
void | EffectCleanup
DependencyList
type DependencyList = readonly unknown[];Defined in: react/types.ts:76
A list of dependencies passed to hooks (e.g. useEffect, useMemo, useCallback).
EventMapping
type EventMapping = object;Defined in: react/types.ts:85
Single source of truth: React handler prop name -> Native Factorio event payload structure.
Properties
| Property | Type | Defined in |
|---|---|---|
onClick | Color | react/types.ts:86 |
onClosed | Color | react/types.ts:87 |
onConfirmed | Color | react/types.ts:88 |
onTextChanged | Color | react/types.ts:89 |
onCheckedStateChanged | Color | react/types.ts:90 |
onElemChanged | Color | react/types.ts:91 |
onValueChanged | Color | react/types.ts:92 |
onSelectionStateChanged | Color | react/types.ts:93 |
onSwitchStateChanged | Color | react/types.ts:94 |
onSelectedTabChanged | Color | react/types.ts:95 |
onHover | Color | react/types.ts:96 |
onLeave | Color | react/types.ts:97 |
onLocationChanged | Color | react/types.ts:98 |
onOpened | Color | react/types.ts:99 |
GuiEventData
type GuiEventData = EventMapping[keyof EventMapping];Defined in: react/types.ts:103
Union of all possible native Factorio GUI event payloads.
GuiEventHandler
type GuiEventHandler<K, T> = (this: void, event: TypedEvent<EventMapping[K], T>) => void;Defined in: react/types.ts:115
Generic strongly-typed handler for native Factorio GUI events.
Type Parameters
| Type Parameter | Default type |
|---|---|
K extends keyof EventMapping | - |
T extends Color | Color |
Parameters
| Parameter | Type |
|---|---|
this | void |
event | TypedEvent<EventMapping[K], T> |
Returns
void
Key
type Key = string | number;Defined in: react/types.ts:191
Unique identifier used by the reconciler to match and preserve fiber state across renders.
ReactNode
type ReactNode = | ReactElement<any> | boolean | undefined | ReactNode[];Defined in: react/types.ts:199
Anything that can be rendered as JSX children:
- A virtual element (
<Button />,<Frame />) - Primitives for conditional rendering (
boolean,undefined) - An array of child nodes
ElementType
type ElementType<P> = | Color| ComponentType<P>;Defined in: react/types.ts:206
Valid element constructor or tag identifier:
- Native Factorio primitive tag name (
"button" | "textfield" | "flow" | ...) - Custom functional component (
ComponentType<P>)
Type Parameters
| Type Parameter | Default type |
|---|---|
P extends Props | Props |
ComponentType
type ComponentType<P> = (this: void, props: P) => ReactNode;Defined in: react/types.ts:225
Functional component blueprint: a pure or stateful function that accepts props and returns a ReactNode.
Represents the component definition itself (the factory/recipe), as opposed to an instantiated <ReactElement />.
Type Parameters
| Type Parameter | Default type |
|---|---|
P extends Props | Props |
Parameters
| Parameter | Type |
|---|---|
this | void |
props | P |
Returns
FiberId
type FiberId = number;Defined in: react/types.ts:239
Unique numeric identifier for a virtual Fiber node.
RootId
type RootId = number;Defined in: react/types.ts:242
Unique numeric identifier for a mounted React root tree.
EntityDestroyedEvent
type EntityDestroyedEvent = | Color | Color | Color | Color | Color;Defined in: react/types.ts:359
Union of all Factorio event payloads that signal entity destruction or mining.
EntityBuiltEvent
type EntityBuiltEvent = | Color | Color | Color | Color | Color;Defined in: react/types.ts:362
Union of all Factorio event payloads that signal entity placement, ghost construction, or revival.
PrimitiveProps
type PrimitiveProps<T> = NativePropsFor<T> & ReactInternalProps<T> & EventHandlersFor<T>;Defined in: react/types.ts:430
Combined props for a native Factorio element T:
- Native Factorio element properties (
NativePropsFor) - React internal props (
children,styles,style,ref) - Strictly typed event handlers (
EventHandlersFor)
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends Color | Color |
Variables
componentRegistry
const componentRegistry: Record<string, | ComponentType<any> | undefined> = {};Defined in: react/index.ts:183
In-memory registry of root component functions keyed by unique string names.
Factorio cannot serialize Lua closures/functions into storage.
During game save, root descriptors store string component identifiers (rootType).
On game load (on_load), the engine looks up the component function in this
registry to rehydrate the virtual DOM tree and reattach event handlers.
transientStates
const transientStates: Record<FiberId, | TransientState | undefined> = {};Defined in: react/index.ts:240
In-memory transient state map for all active Fiber nodes. Stores non-serializable objects (C++ LuaGuiElement references, closures, cleanups, memo cache). This RAM-only table is never written to disk and is safely reconstructed during hydration.
Functions
createElement()
function createElement<P>( type: any, props?: P, ...children: ReactNode[]): ReactElement<P>;Defined in: react/index.ts:104
Creates a virtual React element descriptor.
Type Parameters
| Type Parameter | Default type |
|---|---|
P extends Props | Props |
Parameters
| Parameter | Type | Description |
|---|---|---|
type | any | Component function or primitive Factorio tag name (e.g. “flow”, “button”) |
props? | P | Element props object |
…children? | ReactNode[] | Child elements |
Returns
ReactElement<P>
A virtual ReactElement object
Fragment()
function Fragment(props: object): ReactNode;Defined in: react/index.ts:129
Fragment component to group multiple JSX elements without a wrapper DOM node.
Parameters
| Parameter | Type |
|---|---|
props | { children?: ReactNode; } |
props.children? | ReactNode |
Returns
registerComponent()
function registerComponent<T>(name: string, component: T): T;Defined in: react/index.ts:195
Registers a root component function under a unique string name.
Must be called at top-level module load time so that on_load can find it.
Type Parameters
| Type Parameter |
|---|
T extends ComponentType<any> |
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Unique component identifier (e.g. “my-mod-main-gui”) |
component | T | The functional component |
Returns
T
The passed component function
getComponentTypeName()
function getComponentTypeName(elementType: any): string;Defined in: react/index.ts:213
Resolves a human-readable registry name for a component or native tag name.
Uses a zero-cost O(1) LuaTable lookup for functional components.
Parameters
| Parameter | Type | Description |
|---|---|---|
elementType | any | Component function or native tag name |
Returns
string
Resolved string name
getComponentType()
function getComponentType(elementType: any): any;Defined in: react/index.ts:228
Resolves an ElementType from a registered name or passes through the component function / native tag.
Parameters
| Parameter | Type | Description |
|---|---|---|
elementType | any | Component function, native tag name, or registered component string identifier |
Returns
any
Resolved ComponentType or native tag string
fiberTrace()
function fiberTrace(fiber: Fiber): string;Defined in: react/index.ts:248
Formats a Fiber node and its hierarchy context into a compact string for structured logging.
Parameters
| Parameter | Type | Description |
|---|---|---|
fiber | Fiber | Target Fiber node |
Returns
string
Formatted debug string, e.g. #14<SlotButton key=slot-3 parent=#10<SectionGroup> root=#1>
createFiber()
function createFiber(type: string, key?: Key): Fiber;Defined in: react/index.ts:270
Allocates a new serializable Fiber node and initializes its RAM transient state.
Parameters
| Parameter | Type | Description |
|---|---|---|
type | string | Component name or native tag name |
key? | Key | Optional reconciliation key |
Returns
The newly allocated Fiber node
getTransient()
function getTransient(id: number): TransientState;Defined in: react/index.ts:293
Retrieves or initializes the in-memory RAM TransientState for a given Fiber ID.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | number | Unique numeric Fiber ID |
Returns
The TransientState record
getHook()
function getHook(fiberId: number, idx: number): HookInstance;Defined in: react/index.ts:309
Retrieves or lazily creates an in-memory HookInstance for the given Fiber ID and hook slot.
Parameters
| Parameter | Type | Description |
|---|---|---|
fiberId | number | Unique Fiber node ID |
idx | number | Zero-based hook slot index |
Returns
HookInstance
The HookInstance container
assignRef()
function assignRef(ref: Ref, value: any): void;Defined in: react/index.ts:331
Assigns a native Factorio LuaGuiElement reference to a React ref.
Supports both function callbacks ((elem) => ...) and mutable ref objects ({ current: elem }).
Parameters
| Parameter | Type | Description |
|---|---|---|
ref | Ref | Ref callback or MutableRefObject |
value | any | Native GUI element or undefined on unmount |
Returns
void
createGuiElement()
function createGuiElement( parent: LuaGuiElement, type: GuiElementType, props: Props, fiberId: number): LuaGuiElement;Defined in: react/index.ts:372
Creates a new native Factorio LuaGuiElement inside a parent container.
Segregates creation properties from post-creation properties based on ELEMENT_SCHEMA,
applies styles and style overrides, pre-indexes event handlers for O(1) integer table dispatch,
tags the element with __reactId, and attaches the ref.
Parameters
| Parameter | Type | Description |
|---|---|---|
parent | LuaGuiElement | Native Factorio GUI parent container |
type | GuiElementType | Native element type name (e.g. “button”, “frame”, “flow”) |
props | Props | Virtual element props |
fiberId | number | Unique Fiber node ID |
Returns
LuaGuiElement
The created native LuaGuiElement
updateGuiElement()
function updateGuiElement( elem: LuaGuiElement, props: Props, fiberId: number, prevProps?: Props): void;Defined in: react/index.ts:428
Updates an existing native Factorio LuaGuiElement by diffing current props against previous props.
Only writes modified values to the Factorio C++ engine boundary to minimize cross-language overhead.
Reapplies style overrides if the prototype style changed, updates pre-indexed event handlers, and updates refs.
Parameters
| Parameter | Type | Description |
|---|---|---|
elem | LuaGuiElement | Live native LuaGuiElement |
props | Props | Next virtual element props |
fiberId | number | Unique Fiber node ID |
prevProps? | Props | Previous virtual element props |
Returns
void
findFirstGuiElement()
function findFirstGuiElement(fiber: Fiber): any;Defined in: react/index.ts:491
Recursively traverses a Fiber subtree to find the first real LuaGuiElement. This is needed because Functional Components do not own a native element directly.
Parameters
| Parameter | Type | Description |
|---|---|---|
fiber | Fiber | Target Fiber node |
Returns
any
The first matching valid LuaGuiElement or undefined
destroyGuiElement()
function destroyGuiElement(elem: any): void;Defined in: react/index.ts:511
Safely destroys a native Factorio GUI element if it exists and is still valid.
Parameters
| Parameter | Type | Description |
|---|---|---|
elem | any | LuaGuiElement to destroy |
Returns
void
beginHookRender()
function beginHookRender(fiber: Fiber, hydrating: boolean): void;Defined in: react/index.ts:532
Prepares the global hook cursor before rendering a functional component.
Parameters
| Parameter | Type | Description |
|---|---|---|
fiber | Fiber | Active Fiber node being rendered |
hydrating | boolean | True if hydrating from storage on game load |
Returns
void
endHookRender()
function endHookRender(): void;Defined in: react/index.ts:541
Cleans up the global hook cursor after component render.
Returns
void
useState()
Call Signature
function useState<S>(initialValue: (this: void) => NonFunction<S>): [S, Dispatch<SetStateAction<S>>];Defined in: react/index.ts:567
Declares a stateful variable in a functional component.
State is preserved in the serializable fiber.hooks array across renders and game saves.
The setState updater closure is cached in transient.memoCache on initial mount,
resulting in zero closure allocations on subsequent re-renders.
Type Parameters
| Type Parameter |
|---|
S |
Parameters
| Parameter | Type |
|---|---|
initialValue | (this: void) => NonFunction<S> |
Returns
[S, Dispatch<SetStateAction<S>>]
A tuple of [currentState, setState]
Call Signature
function useState<S>(initialValue: NonFunction<S>): [S, Dispatch<SetStateAction<S>>];Defined in: react/index.ts:568
Declares a stateful variable in a functional component.
State is preserved in the serializable fiber.hooks array across renders and game saves.
The setState updater closure is cached in transient.memoCache on initial mount,
resulting in zero closure allocations on subsequent re-renders.
Type Parameters
| Type Parameter |
|---|
S |
Parameters
| Parameter | Type |
|---|---|
initialValue | NonFunction<S> |
Returns
[S, Dispatch<SetStateAction<S>>]
A tuple of [currentState, setState]
flushPendingEffects()
function flushPendingEffects(): void;Defined in: react/index.ts:605
Flushes all queued side-effects after the component tree and GUI elements are committed.
Returns
void
useEffect()
function useEffect(effect: EffectCallback, deps?: DependencyList): void;Defined in: react/index.ts:650
Side-effect hook. Queued and executed in the commit phase after GUI elements are attached. Cleans up previous effect return callback before re-running or on unmount.
Parameters
| Parameter | Type |
|---|---|
effect | EffectCallback |
deps? | DependencyList |
Returns
void
useReducer()
function useReducer<S, A>( reducer: (this: void, prevState: S, action: A) => S, initialArg: NonFunction<S>, init?: (this: void, initial: S) => NonFunction<S>): [S, (this: void, action: A) => void];Defined in: react/index.ts:677
Reducer hook for managing complex state transitions. Dispatches actions to compute the next state based on the reducer function.
Type Parameters
| Type Parameter |
|---|
S |
A |
Parameters
| Parameter | Type | Description |
|---|---|---|
reducer | (this: void, prevState: S, action: A) => S | State transition function (prevState, action) => nextState |
initialArg | NonFunction<S> | Initial state value |
init? | (this: void, initial: S) => NonFunction<S> | Optional lazy initialization function |
Returns
[S, (this: void, action: A) => void]
A tuple of [state, dispatch]
useMemo()
function useMemo<T>(factory: (this: void) => T, deps: DependencyList): T;Defined in: react/index.ts:701
Caches a computed value in transient RAM memory (hook.memo).
Recomputes the value only when one of the specified dependencies changes,
or during game hydration if the RAM cache was reset.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
factory | (this: void) => T | Pure function that computes the value |
deps | DependencyList | Dependency array for change detection |
Returns
T
The memoized value
useCallback()
function useCallback<T>(callback: T, deps: DependencyList): T;Defined in: react/index.ts:726
Returns a memoized version of the callback function that only changes if dependencies change.
Type Parameters
| Type Parameter |
|---|
T extends (this: void, …args: any[]) => any |
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | T | Function to memoize |
deps | DependencyList | Dependency array |
Returns
T
The stable callback reference
useRef()
Call Signature
function useRef<T>(initialValue: T): object;Defined in: react/index.ts:737
Returns a mutable ref object whose .current property is initialized to the passed argument.
The returned object persists in transient RAM across the component’s lifetime.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
initialValue | T | Initial value assigned to ref.current |
Returns
object
A mutable container { current: T }
| Name | Type | Defined in |
|---|---|---|
current | T | react/index.ts:737 |
Call Signature
function useRef<T>(): object;Defined in: react/index.ts:738
Returns a mutable ref object whose .current property is initialized to the passed argument.
The returned object persists in transient RAM across the component’s lifetime.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | undefined |
Returns
object
A mutable container { current: T }
| Name | Type | Defined in |
|---|---|---|
current | T | react/index.ts:738 |
useDebouncedCallback()
function useDebouncedCallback<A>(callback: (this: void, ...args: A) => void, delayTicks?: number): (this: void, ...args: A) => void;Defined in: react/index.ts:778
Returns a debounced callback function that postpones execution until delayTicks game ticks
have elapsed since the last invocation. Uses the global bucketed scheduler.
Automatically cancels any pending execution on component unmount.
Type Parameters
| Type Parameter |
|---|
A extends any[] |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
callback | (this: void, …args: A) => void | undefined | Function to debounce |
delayTicks | number | 30 | Number of game ticks to wait before invocation (default: 30 ticks = 0.5s) |
Returns
The debounced callback function
(this: void, …args: A) => void
useInterval()
function useInterval(callback: (this: void) => void, intervalTicks?: number): void;Defined in: react/index.ts:849
Executes a periodic callback at the specified interval using the high-performance bucketed scheduler.
Automatically pauses if intervalTicks is 0 or negative.
Automatically deregisters the scheduled timer on component unmount or interval change.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (this: void) => void | Callback invoked every interval |
intervalTicks? | number | Interval in game ticks (e.g. 60 ticks = 1 second). Pass <= 0 or undefined to pause. |
Returns
void
useWindow()
function useWindow(playerIndex: PlayerIndex, options?: UseWindowOptions): UseWindowReturn;Defined in: react/index.ts:879
Comprehensive window management hook for top-level dialogs (WindowFrame).
Handles opening, closing, keyboard shortcuts (‘E’/Escape), pinning persistence,
auto-centering, and position memory across game sessions.
Parameters
| Parameter | Type | Description |
|---|---|---|
playerIndex | PlayerIndex | Factorio player index |
options? | UseWindowOptions | Optional window options configuration |
Returns
Window controller interface with close, pinned, setPinned, togglePin, onLocationChanged
useEntityLifecycle()
function useEntityLifecycle(entity: any, callbacks: EntityLifecycleCallbacks): void;Defined in: react/index.ts:1047
Observes a LuaEntity lifecycle (destruction, mining, blueprint revival) and executes callbacks.
Automatically tracks entity position, surface, and unit number to handle rebuilds and ghost revivals.
Parameters
| Parameter | Type | Description |
|---|---|---|
entity | any | The Factorio entity to track |
callbacks | EntityLifecycleCallbacks | Lifecycle callback handlers (onDestroyed, onRevived) |
Returns
void
arePropsEqual()
function arePropsEqual(prevProps?: Props, nextProps?: Props): boolean;Defined in: react/index.ts:1176
Compares component props for shallow equality to determine if reconciliation can be bailed out.
Automatically ignores stable function callbacks and performs deep comparison on styles overrides.
Parameters
| Parameter | Type | Description |
|---|---|---|
prevProps? | Props | Previous props |
nextProps? | Props | Next props |
Returns
boolean
True if props are functionally identical
scheduleUpdate()
function scheduleUpdate(fiber: Fiber): void;Defined in: react/index.ts:1203
Marks a Fiber and its parent branch as dirty, and schedules a deferred sub-tick render pass
via an ephemeral rendering.draw_line object destruction trigger.
Parameters
| Parameter | Type | Description |
|---|---|---|
fiber | Fiber | The Fiber node requesting a re-render |
Returns
void
performDeferredUpdates()
function performDeferredUpdates(roots?: Record<RootId, ReactRootData | undefined>): void;Defined in: react/index.ts:1238
Processes all dirty Fiber roots in a single batch pass, re-rendering modified components, committing DOM updates, and flushing all queued side-effects.
Parameters
| Parameter | Type | Description |
|---|---|---|
roots? | Record<RootId, ReactRootData | undefined> | Table of active React roots in global storage |
Returns
void
reconcile()
function reconcile( element: ReactElement, oldFiber: Fiber, parentElem: LuaGuiElement, parentFiber?: Fiber, root?: ReactRootData): Fiber;Defined in: react/index.ts:1279
Core React reconciliation and diffing algorithm.
Compares a new ReactElement virtual descriptor against an existing Fiber node.
Evaluates bailouts, executes functional components, creates or mutates native GUI widgets,
and recursively reconciles children.
Parameters
| Parameter | Type | Description |
|---|---|---|
element | ReactElement | Virtual React element descriptor |
oldFiber | Fiber | Existing Fiber node from previous render pass |
parentElem | LuaGuiElement | Native Factorio GUI parent container |
parentFiber? | Fiber | Direct parent Fiber node in the component tree |
root? | ReactRootData | Enclosing React root metadata |
Returns
The updated or newly created Fiber node
createRoot()
function createRoot(container: LuaGuiElement, element: ReactElement): number;Defined in: react/index.ts:1457
Mounts a root React element into a native Factorio GUI container (e.g. player.gui.screen).
Parameters
| Parameter | Type | Description |
|---|---|---|
container | LuaGuiElement | Native Factorio GUI parent container |
element | ReactElement | Root ReactElement (e.g. <CombinatorWindow playerIndex={playerIndex} />) |
Returns
number
Unique numeric Root ID
destroyRoot()
function destroyRoot(rootId: number): void;Defined in: react/index.ts:1496
Unmounts a root React tree, disposes all child fibers and GUI elements, and removes the root entry from persistent global storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
rootId | number | Root identifier returned by createRoot |
Returns
void
hydrateFiber()
function hydrateFiber( element: ReactElement, fiber: Fiber, parentElem: LuaGuiElement, parentFiber?: Fiber, root?: ReactRootData): void;Defined in: react/index.ts:1522
Recursively hydrates an existing Fiber tree during game on_load.
Restores non-serializable RAM transient state (event handlers, memo caches, and live LuaGuiElement C++ references)
matching native DOM tags without modifying game storage or mutating the DOM.
Parameters
| Parameter | Type | Description |
|---|---|---|
element | ReactElement | Root virtual element descriptor |
fiber | Fiber | Root Fiber node loaded from storage.reactRoots |
parentElem | LuaGuiElement | Native Factorio GUI container |
parentFiber? | Fiber | Direct parent Fiber node in the component tree |
root? | ReactRootData | Enclosing React root metadata |
Returns
void
handleOnLoad()
function handleOnLoad(): void;Defined in: react/index.ts:1613
Hydrates all active React roots during game on_load.
Iterates all active roots stored in storage.reactRoots and re-attaches transient RAM state.
Returns
void
handleOnObjectDestroyed()
function handleOnObjectDestroyed(ev: OnObjectDestroyedEvent): void;Defined in: react/index.ts:1634
Handles deferred subtick render trigger via object destruction. Invoked when the ephemeral rendering line object is destroyed to batch-flush all dirty updates.
Parameters
| Parameter | Type | Description |
|---|---|---|
ev | OnObjectDestroyedEvent | Factorio on_object_destroyed event payload |
Returns
void
handleGuiEvent()
function handleGuiEvent(event: any): void;Defined in: react/index.ts:1648
Global high-performance O(1) Factorio GUI event dispatcher.
Resolves the target Fiber ID from event.element.tags.__reactId and dispatches directly
to the pre-indexed handler in transient.handlers without string matching or tree traversal.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | any | Factorio GUI event payload |
Returns
void
bootstrapReact()
function bootstrapReact(): void;Defined in: react/index.ts:1677
Bootstraps the React runtime by registering core Factorio event listeners:
on_load hydration, sub-tick deferred render trigger, and all GUI interaction events.
Returns
void
References
areObjectsEqual
Re-exports areObjectsEqual