swap to roact-hooked, init roact-reflex

This commit is contained in:
Reid 2023-08-15 17:58:36 -07:00
parent 3530d84142
commit cfccbe4883
14 changed files with 109 additions and 141 deletions

View file

@ -1,31 +1,16 @@
import { World } from "@rbxts/matter"
import Roact, { createContext } from "@rbxts/roact"
import Hooks, { CoreHooks } from "@rbxts/roact-hooks"
import Roact from "@rbxts/roact"
import { useContext } from "@rbxts/roact-hooked"
import { clientState } from "ReplicatedStorage/ecs/state"
interface WorldContextValue {
interface worldContextProps {
world: World
clientState: clientState
}
interface Props {
world: World
clientState: clientState
}
export const WorldContext = Roact.createContext<worldContextProps | undefined>(undefined)
const WorldProviderWithoutHooks: Hooks.FC<Props> = (props) => {
const { world, clientState } = props
return <WorldContext.Provider value={{ world, clientState }}>{props[Roact.Children]}</WorldContext.Provider>
}
const WorldProvider = new Hooks(Roact)(WorldProviderWithoutHooks)
export default WorldProvider
const WorldContext = createContext<WorldContextValue | undefined>(undefined)
export const useWorldContext = ({ useContext }: CoreHooks): WorldContextValue => {
export function useWorldContext(): worldContextProps {
const context = useContext(WorldContext)
if (!context) {
error("useContext must be called within a Provider")