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
slainlessOP7mo ago
use theme signal impl:
export function useThemeSignal() {
return useContext(ThemeContext)
}
export function useThemeSignal() {
return useContext(ThemeContext)
}
Brendonovich
Brendonovich7mo ago
This is a funny one, you're calling the Story() outside of the provider, so it doesn't have access
slainless
slainlessOP7mo ago
wait...
Brendonovich
Brendonovich7mo ago
It might work to just pass Story without calling it since functions as children is valid
slainless
slainlessOP7mo ago
ah is that so
Brendonovich
Brendonovich7mo ago
You'd be better off just using JSX though if possible
slainless
slainlessOP7mo 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
Brendonovich7mo 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
slainlessOP7mo ago
aha many thanks for your help man 🙏
Want results from more Discord servers?
Add your server