mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
* refactor!: create monorepo * chore: prepare release, set up workflows * refactor: rename `modules` to `src` * docs: add docs for all packages * refactor: rename root project file * chore: bump deps * build: rename `lint`, add `pack` script * revert: delete pack script This will not be useful for development.
42 lines
945 B
Text
42 lines
945 B
Text
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
|
|
|
_G.__ROACT_17_MOCK_SCHEDULER__ = true
|
|
|
|
local React = require(ReplicatedStorage.DevPackages.React)
|
|
local ReactRoblox = require(ReplicatedStorage.DevPackages.ReactRoblox)
|
|
|
|
type RenderedHook<Props, Result> = {
|
|
result: Result,
|
|
rerender: (Props?) -> (),
|
|
unmount: () -> (),
|
|
}
|
|
|
|
local function renderHook<Props, Result>(callback: (Props) -> Result, props: Props?): RenderedHook<Props, Result>
|
|
local root = ReactRoblox.createLegacyRoot(Instance.new("Folder"))
|
|
local hook = {}
|
|
|
|
local function Component(props)
|
|
hook.result = callback(props)
|
|
end
|
|
|
|
function hook.rerender(newProps)
|
|
props = newProps or props
|
|
ReactRoblox.act(function()
|
|
root:render(React.createElement(Component, props))
|
|
end)
|
|
end
|
|
|
|
function hook.unmount()
|
|
ReactRoblox.act(function()
|
|
root:unmount()
|
|
end)
|
|
end
|
|
|
|
ReactRoblox.act(function()
|
|
hook.rerender(props)
|
|
end)
|
|
|
|
return hook
|
|
end
|
|
|
|
return renderHook
|