Access current value within the template
Hi,
Is there a way to get the currently selected value of root attribute from within a template?
Something like:
...
rootAttribute: {
defaultState: {
name: "Dark",
value: "dark"
},
states: [
{
name: "Light",
value: null
}
]
},
...
const Template: Story = (state, context) => (
context.rootAttribute // returns "dark"
);
@colorfulfool how about read it from DOM?
Should be possible with a mutation observer, I guess. But it the app itself the theme (dark/light) is placed in Redux, from where it's synced to DOM. Appearance is mostly influenced by CSS that the DOM attribute triggers, but some components access the theme directly. So it would make sense to be able to inject the current value into Redux?
So it would make sense to be able to inject the current value into Redux?
Yes, it make sense. Also some devs using context to pass "theme" to components
So, is it possible?
To inject the value into story's Redux provider, I need to access the value from the story somehow.