SolidJSS
SolidJS3y ago
43 replies
Mathieu

Parent setting prop to child with Context?

Say I have the following component:
<ToggleButtonGroup onChange={handleToggleChange}>
  <ToggleButton id="key">
    Foo
  </ToggleButton>
  <ToggleButton id="anotherKey">
    Bar
  </ToggleButton>
  <ToggleButton id="andAnotherKey">
    Baz
  </ToggleButton>
</ToggleButtonGroup>

A context provider allows the children ToggleButton to access onChange in order to call this callback when a toggle is clicked.

Question: how can I set the default selected toggle (when none is provided as above) as "key"? As far as I know there might be no way.
Was this page helpful?