We should implement our own wrapper around context that would be fully typed.
api ideas:
froact.provide, makes the type for Context smaller, by not including Provider:
local context = froact.createContext({ hello = "world" }) -- infered type: Context<{ hello = "world" }>
local bah = froact.c({}, function(props, hooks)
local value = hooks.useContext(context)
return TextLabel({ text = `hello is {value.hello}` })
end
local element = froact.provide(context, { hello = "foo" }, {
bah({})
})
similar to react
local context = froact.createContext({ hello = "world" } -- infered type: Context<{ hello = "world" }>
local bah = froact.c({}, function(props, hooks)
local value = hooks.useContext(context)
return TextLabel({ text = `hello is {value.hello}` })
end
local element = context.Provider({
value = { hello = "foo" }
}, {
bah({})
})
Context<T> should be { default: T, Provider: ({ value: T }) -> Element }, Consumer: any (too lazy to define consumer, you shouldn't use consumer, use the hook instead)
We should implement our own wrapper around context that would be fully typed.
api ideas:
froact.provide, makes the type for Context smaller, by not including Provider:
similar to react
Context<T>
should be{ default: T, Provider: ({ value: T }) -> Element }, Consumer: any
(too lazy to define consumer, you shouldn't use consumer, use the hook instead)