-
Hi is it possible to access the context from children component, e.g. the open state of the Dialog component, from the Dialog.Content component, is that possible? |
Beta Was this translation helpful? Give feedback.
Answered by
jjenzz
Jan 13, 2024
Replies: 1 comment
-
Radix components all provide a controlled API to share state: const [open, setOpen] = React.useState(false);
return (
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Content>
{/* now child parts can have access to its state */}
{open ? 'open' : null}
</Dialog.Content>
</Dialog.Root>
); this behaves much like the way you would share const [value, setValue] = React.useState('');
return (
<>
<input value={value} onChange={e => setValue(e.currentTarget.value)} />
{/* share value with another component */}
<SomethingElse inputValue={value} />
</>
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
benoitgrelard
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Radix components all provide a controlled API to share state:
this behaves much like the way you would share
<input />
state with other components: