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