Lesson 4 of 6

UI frameworks, part 2: the React-lua shop, Fusion, Vide and when to use one

Part 2 of 2 on Roblox UI frameworks, walking through Beacon Yard's m09-react-shop in React-lua, adding a pure reducer pattern, and comparing Fusion, Vide, roblox-ts and plain Instances honestly.

Project lesson, about 65 minutes, 9 steps

By the end you can

  • Read Beacon Yard's m09-react-shop implementation (ShopGui, ShopApp, ShopButton and ShopLabels) and extend it with a pure reducer
  • Keep purchases on the server while React-lua UI shows pending, bought and denied states
  • Compare React-lua, Fusion, Vide, roblox-ts and plain Instances, and decide when a framework is worth it

Before this: UI frameworks, part 1: React-lua, elements, props and state

Step 1 of 9

The shop, as a tree of components

Part 1 installed React-lua and introduced elements, props, state and effects. Now look at the whole shop in m09-react-shop. init.client.luau still calls ShopGui.start(), which builds the BeaconShop ScreenGui, attaches UiScale, and portals ShopApp into it. Inside src/client/ShopApp.luau, ShopApp owns the state (open, coins, textScale) with React.useState and renders a Frame with one ShopButton per item:

text
ShopGui.start() -> ScreenGui "BeaconShop" (UiScale)
└─ ShopApp (useState: open, coins, textScale; useRef: popRef, speedRef)
   ├─ Title       "Quartermaster"
   ├─ Wallet      ShopLabels.wallet(coins)
   ├─ ShopButton  Speed     ShopLabels.item(...)
   ├─ ShopButton  Shield    ShopLabels.item(...)
   ├─ ShopButton  CoinPack  ShopLabels.pack(...)
   └─ Close       TextButton

The prices still come from Config, the Coin Pack still checks Ids.COIN_PACK_PRODUCT_ID, and pure button text formatting lives in src/shared/ShopLabels.luau. Nothing about the server changes.

local function ShopApp(props: ShopProps)
	local player = Players.LocalPlayer
	if player == nil then
		error("ShopApp must run on the client")
	end
 
	local open, setOpen = React.useState(false)
	local coins, setCoins = React.useState(readCoins(player))
	local textScale, setTextScale = React.useState(Accessibility.textScale())
	local popRef = React.useRef(nil :: UIScale?)
	local speedRef = React.useRef(nil :: TextButton?)

ShopButton in ShopApp.luau replaces the old hand-built buyButton helper from m06-drone-wrench, and adds a focus ring driven by its own focused state.

Choose one

Which component owns the open flag in ShopApp.luau?

Which component owns the open flag in ShopApp.luau?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 2 of 9

Growing past useState: one reducer for every shop change

m09-react-shop keeps ShopApp small with three useState calls (open, coins, textScale) and lets SoundClient show toast messages for Feedback. Once a screen also needs a pending state (disabling the button while waiting for the server) and an inline status message, several useState setters have to stay in sync. A reducer solves that: it is a pure function that takes the current state and an action and returns the next state. React.useReducer runs it for you, and because it is pure, you can test it without Studio (as you will in the challenges).

Luau
Ctrl Enter runs the cell. Checked against the expected output
Predict the output

After the four lines above, the player presses Close. What is pending?

local s4 = reduce(s3, { type = "close" })
show(s4.pending, s4.open)
After the four lines above, the player presses Close. What is pending?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 3 of 9

Wiring remotes in effects

This is a sketch, not the repo's code: m09-react-shop has no ShopScreen, Panel or useReducer, and its ShopApp uses three useState calls. The sketch shows how the reducer version of the shop would connect two remotes in effects and send one. reduce is the function from the cell above, and Panel is a component you would write to draw the shop from state. ShopOpen dispatches open. Feedback dispatches feedback with the text the server sent. A click dispatches buy and fires ShopBuy.

luau
-- Sketch: assumes `React`, `e = React.createElement`, `reduce` and `Panel` exist.
local function ShopScreen(props)
	local state, dispatch = React.useReducer(reduce, { open = false })
 
	React.useEffect(function()
		local opened = props.shopOpen.OnClientEvent:Connect(function()
			dispatch({ type = "open" })
		end)
		local replied = props.feedback.OnClientEvent:Connect(function(kind, text)
			if kind == "buy" or kind == "deny" then
				dispatch({ type = "feedback", text = text })
			end
		end)
		return function()
			opened:Disconnect()
			replied:Disconnect()
		end
	end, {})
 
	local function buy(item)
		dispatch({ type = "buy", item = item })
		props.shopBuy:FireServer(item)
	end
 
	return e(Panel, { state = state, buy = buy, close = function()
		dispatch({ type = "close" })
	end })
end

You would mount it once from the client entry script with ReactRoblox.createRoot and a portal into PlayerGui, the way ShopGui.start() mounts ShopApp in the build along of part 1.

The buy button still only writes a note to the front desk. The reducer's pending state is the UI admitting it is waiting for the clerk. The coins on screen do not move until the server's reply arrives.

Think of it as A note to the front-desk clerk

Both sidesRemember: A RemoteEvent is a note to the front-desk clerk.

Choose all that apply

The server's Feedback remote sends a kind and an optional text. Which kinds should end the pending state in the shop?

The server's Feedback remote sends a kind and an optional text. Which kinds should end the pending state in the shop?

Press 1 to 5 to choose, Enter to check.

Link to this step · This confused me

Step 4 of 9

Where the front desk breaks, again

Where does it break?“A note to the front-desk clerk” is a good picture of a remoteevent. Where does it stop being true?

It breaks here. The engine stamps the sender for you, but every other word on the note can be a lie.

The true model. A RemoteEvent carries a one-way message between a client and the server. The server always learns which player sent it; every other argument is untrusted input that the server must check.

A React UI is still a client. A cheater can call dispatch, fake a bought state, or fire ShopBuy with any string. None of that matters, because ShopService checks the item name, the price and the balance on the server. Moving the UI to React changes how the screen is drawn, never who decides.

Choose one

An exploiter edits the React tree so the Speed button reads 0 coins and fires ShopBuy("Speed"). What happens?

An exploiter edits the React tree so the Speed button reads 0 coins and fires ShopBuy("Speed"). What happens?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 5 of 9

Fusion, Vide, and plain Instances

React is not the only way to describe UI from state. Here is the same coin label in two other libraries.

luau
-- Fusion 0.3: values live in a scope; Computed reads them with use().
local scope = Fusion.scoped(Fusion)
local coins = scope:Value(0)
scope:New "TextLabel" {
	Text = scope:Computed(function(use)
		return "Coins: " .. use(coins)
	end),
}
coins:set(5)
 
-- Vide: a source is a value you call; a function prop re-runs when it changes.
local coins = vide.source(0)
vide.create "TextLabel" {
	Text = function()
		return "Coins: " .. coins()
	end,
}
coins(5)

Fusion and Vide are reactive: they track which values each property reads and update only that property, with no tree comparison. React re-runs components and compares descriptions. Both work well; they suit different teams12.

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
React-luaA Luau port of React 17 (Roblox/react-luau and jsdotlua/react-lua): components, hooks, reconciliation.Large UIs, teams with web React experience, Roblox's own tooling and testing.Heaviest of the four; React concepts to learn; re-renders need care in hot paths.
FusionA reactive state and UI library; version 0.3 introduced scopes for cleanup.Luau-first teams who like fine-grained reactivity and declarative Instances.Pre-1.0, and APIs have changed between versions.
VideA small reactive library inspired by Solid, fully type-checkable.Performance-minded projects that want minimal API and strong types.Smaller community and fewer learning resources.
roblox-ts with @rbxts/reactTypeScript compiled to Luau, with JSX for React-lua.Studios that hire web developers or want npm-style packages.A second language and compiler between you and Roblox.
Plain InstancesInstance.new and property writes, as Beacon Yard's HUD still does.A HUD of a few labels, a prototype, or one screen that rarely changes.Every state change is a handwritten update, and it grows messy fast.
Match the pairs

Match each situation to the most sensible choice.

Link to this step · This confused me

Step 6 of 9

When a framework is worth it

Beacon Yard keeps the HUD hand-built and moves only the shop to React. That is deliberate. The HUD has a handful of labels driven by one remote, and rewriting it would add a dependency for no gain. The shop has items, prices, a pending state, denial messages and, later, a game pass, which is where hand-built code starts to tangle.

A useful rule: reach for a framework when the same piece of state appears in more than one place on screen, or when you catch yourself writing "update the label" in several handlers.

Choose one

Why does Beacon Yard leave the HUD hand-built?

Why does Beacon Yard leave the HUD hand-built?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 7 of 9

Build along: the React-lua shop in m09-react-shop

  • wally.toml
  • default.project.json
  • src/client/ShopGui.luau
  • src/client/ShopApp.luau
  • src/shared/ShopLabels.luau
  1. In the game repo, run git diff --stat m08-crawler m09-react-shop -- src wally.toml default.project.json.

    You should see git lists ShopApp.luau and ShopLabels.luau as new files, wally.toml adds React and ReactRoblox, and ShopGui.luau shrinks from about 370 lines to a thin mount wrapper.

  2. Check out m09-react-shop, run wally install, and read src/client/init.client.luau and src/client/ShopGui.luau.

    You should see init.client.luau still calls ShopGui.start(), and ShopGui.luau creates BeaconShop with UiScale and mounts ShopApp through ReactRoblox.createRoot and createPortal.

  3. Open src/client/ShopApp.luau and src/shared/ShopLabels.luau and trace how ShopButton renders each item and dims buttons you cannot afford.

    You should see ShopApp.luau holds open, coins and textScale with React.useState, subscribes to ShopOpen, leaderstats.Coins and Accessibility in React.useEffect with cleanups, and formats button text through ShopLabels.

  4. Run rojo serve, connect Studio, press Play, open the shop, buy an item, and run game.ServerScriptService.RunGameTests:Invoke() from the server command bar.

    You should see Holding the quartermaster prompt opens BeaconShop, collecting coins updates the Wallet and item labels live, and ServerScriptService.RunGameTests:Invoke() still passes.

Link to this step · This confused me

Step 8 of 9

Challenges

Level 2, Builder

Challenge

Extend ShopApp.luau with the reducer pattern from this lesson: show a pending state on the button that was pressed, clear it on Feedback, and block double clicks while it waits.

Start from
The game at milestone m09 (download)

Done means

  • ShopApp tracks a pending item (with useReducer or useState) and listens to the Feedback remote for buy and deny
  • While an item is pending, its ShopButton shows Waiting and ignores clicks (Active = false)
  • A buy or deny Feedback ends the pending state, and closing the shop clears pending

Meet the criteria above, then record your own result. No test grades this check.

Level 3, Professional

Challenge

Write the shop's reducer and its label function in the learner file challenges/work/ui_react.luau (start from the m14-ship tag in the game repo to get challenges/work/ui_react.luau and challenges/ui-react.luau). The test needs no React-lua runtime and runs on pure Luau. The written solution is challenges/solutions/ui-react.md.

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("ui-react", "ui-react-reducer") in the server command bar. Copy the pass code from Output.

Done means

  • challenges/work/ui_react.luau exports reduce(state, action) and label(name, price, pending, packReady)
  • reduce(state, action) returns a state shaped { open, pending, message } and handles open, buy, feedback, close; unknown actions return the same table, and the input state is never mutated
  • buy sets pending to the item and clears any old message; feedback clears pending and sets message; close clears open, pending and message
  • label returns "Name\nWaiting" when pending == name, "Coin Pack\n50 coins" or "Coin Pack\nset COIN_PACK_PRODUCT_ID" for CoinPack, and "Name\n<price> coins" otherwise
  • challenges/ui-react.luau prints TEST PASS for every check

The Course Runner prints this code when the test passes.

Choose one

Why can the level 3 test check the shop without React or a player?

Why can the level 3 test check the shop without React or a player?

Press 1 to 4 to choose, Enter to check.

Link to this step · This confused me

Step 9 of 9

Recap

Retiring the analogy

You no longer need “a note to the front-desk clerk”. A RemoteEvent carries a one-way message between a client and the server. The server always learns which player sent it; every other argument is untrusted input that the server must check.

Recap

  1. In m09-react-shop, ShopGui.start() mounts ShopApp via ReactRoblox.createRoot and createPortal; ShopApp owns open, coins and textScale with useState and wires remotes and leaderstats in useEffect.
  2. When a screen grows to need pending states and inline messages, a pure reducer with useReducer keeps every transition in one testable function.
  3. React-lua, Fusion, Vide, roblox-ts and plain Instances all work; pick by UI size and team skills, and keep a small HUD hand-built.

A RemoteEvent is a note to the front-desk clerk, until the engine stamps the sender for you, but every other word on the note can be a lie.

Next Audio: recording, editing, licensing, the audio graph

Link to this step · This confused me