feat: use alien-signals

This commit is contained in:
littensy 2025-05-03 18:24:39 -07:00
parent d7a1f62c3c
commit 861ee5acd7
76 changed files with 3112 additions and 1862 deletions

View file

@ -1,8 +1,12 @@
local Charm = require(script.Parent.Charm)
local React = if script.Parent:FindFirstChild("react")
then require(script.Parent.react) :: never
then require((script :: any).Parent.react) :: never
else require(script.Parent.React)
local listen = Charm.listen
local useEffect = React.useEffect
local useState = React.useState
--[=[
A hook that subscribes to changes in the given atom or selector. The
component is re-rendered whenever the state changes.
@ -16,11 +20,10 @@ local React = if script.Parent:FindFirstChild("react")
@return The current state.
]=]
local function useAtom<State>(callback: Charm.Selector<State>, dependencies: { any }?): State
local state, setState = React.useState(callback)
local state, setState = useState(callback)
React.useEffect(function()
setState(callback())
return Charm.subscribe(callback, setState)
useEffect(function()
return listen(callback, setState)
end, dependencies or {})
return state