Skip to content

Mo-sissoko/rbx-rodux-hooks

Repository files navigation

Rodux Hooks

This project takes inspiration from solarhorizon/rodux-hooks in order to make it work with React.

Setup

local RoduxHooks = require(path.to.RoduxHooks)
local store = require(path.to.store)

local useStore = RoduxHooks.useStore
local useSelector = RoduxHooks.useSelector
local useDispatch = RoduxHooks.useDispatch

Api

useStore(): Store
useSelector<S, T>(selector: (S) -> T, equalityFn: ((T, T) -> boolean)?): T
useDispatch(): (action: AnyAction) -> ()

Examples

local app = e(RoduxHooks.Provider, {
    store = store,
}, {
    app = e(App),
})

local root = ReactRoblox.createRoot(Instance.new("Folder"))
root:render(ReactRoblox.createPortal(app, playerGui))
local function MyComponent()
    local counter = useSelector(function(state: store.State)
        return state.counter
    end)

    return e("TextLabel", {
        AnchorPoint = Vector2.new(0.5, 0.5),
        Position = UDim2.fromScale(0.5, 0.5),
        Size = UDim2.fromOffset(200, 100),
        Text = `Count: {counter}`,
    })
end

Contributing

In order to get proper completion, use dev.project.json to build sourcemap.json

rojo sourcemap dev.project.json --output sourcemap.json

About

React hooks for Rodux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages