Skip to content
Discussion options

You must be logged in to vote

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 <input /> state with other components:

const [value, setValue] = React.useState('');

return (
  <>
    <input value={value} onChange={e => setValue(e.currentTarget.value)} />
    {/* share value with another component */}
    <SomethingElse inputValue={value} />
  </>
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by benoitgrelard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants