Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make our own context #14

Open
fewkz opened this issue May 1, 2023 · 0 comments
Open

Make our own context #14

fewkz opened this issue May 1, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@fewkz
Copy link
Owner

fewkz commented May 1, 2023

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)

@fewkz fewkz added the enhancement New feature or request label May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant