Help with context and storybook

Any advice/guess why the consumer is not receiving the value i set on provider and instead got the default value? It definitely works in dev... Thanks.
No description
No description
9 Replies
slainless
slainlessOP6mo ago
use theme signal impl:
export function useThemeSignal() {
return useContext(ThemeContext)
}
export function useThemeSignal() {
return useContext(ThemeContext)
}
Brendonovich
Brendonovich6mo ago
This is a funny one, you're calling the Story() outside of the provider, so it doesn't have access
slainless
slainlessOP6mo ago
wait...
Brendonovich
Brendonovich6mo ago
It might work to just pass Story without calling it since functions as children is valid
slainless
slainlessOP6mo ago
ah is that so
Brendonovich
Brendonovich6mo ago
You'd be better off just using JSX though if possible
slainless
slainlessOP6mo ago
well, i tried with jsx though but still not getting the value eh nvm forgot to pass the value, haha so dumb wait, so what is the equivalent of
<ThemeContext.Provider value={themeSignal}>
<Story />
</ThemeContext.Provider>
<ThemeContext.Provider value={themeSignal}>
<Story />
</ThemeContext.Provider>
in non JSX?
Brendonovich
Brendonovich6mo ago
Something like
ThemeContext.Provider({
children: Story,
value: themeSignal
})
ThemeContext.Provider({
children: Story,
value: themeSignal
})
Or
ThemeContext.Provider({
get children() {
return Story()
},
value: themeSignal
})
ThemeContext.Provider({
get children() {
return Story()
},
value: themeSignal
})
with some extra memoisation on children that jsx automatically inserts
slainless
slainlessOP6mo ago
aha many thanks for your help man 🙏
Want results from more Discord servers?
Add your server