Skip to main content

Quick Start

Reflex is a lightweight state management library that lets you write simple and predictable code to manage state throughout your Roblox game. It is based on the Silo library and is inspired by Redux.

Installation

Reflex is available on npm and Wally:

Terminal
npm install @rbxts/reflex

Start using Reflex

You're now ready to use Reflex! Where Rodux uses stores, reducers, and actions, Reflex revolves around actions and producers. Create a producer with an initial state and a set of actions, and you're ready to go.

import { createProducer } from "@rbxts/reflex";

interface State {
count: number;
}

const initialState: State = {
count: 0,
};

const producer = createProducer(initialState, {
increment: (state) => ({ ...state, count: state.count + 1 }),
reset: (state) => ({ ...state, count: 0 }),
});

Use your producer anywhere

Reflex was designed to make managing your state simple and straightforward. Dispatch actions by calling the action directly, and read & subscribe to state with selectors.

producer.subscribe(
(state) => state.count,
(count) => {
print(`The count is now ${count}`);
},
);

producer.increment(); // The count is now 1