primitives icon indicating copy to clipboard operation
primitives copied to clipboard

[Dialog] Close the dialog after asynchronous form submission without declaring state

Open s97712 opened this issue 9 months ago • 2 comments

Feature request

Overview

Please consider introducing the Dialog.Consume component, which can receive Function as Child Component and pass functions like setOpen to the sub-components.

This can make the code more concise and reduce the burden of state management.

Example:

<Dialog.Consume>
  {({setOpen})=>(
    <Button onClick={async ()=>{
      await submit()
      setOpen(false)
    }} >
      Submit
    </Button>
  )}
</Dialog.Consume>

or

<Dialog.Consume render={({setOpen})=>(
    <Button onClick={async ()=>{
      await submit()
      setOpen(false)
    }} >
      Submit
    </Button>
)}/>

s97712 avatar Apr 24 '24 16:04 s97712

I don't think it would be worth adopting this feature, since the Radix Primitive concept is meant to be more generic. But you can create this yourself in your applications if you really feel the need.

ikidoncc avatar Apr 24 '24 19:04 ikidoncc

I don't understand how this affects its generality. Its idea is the same as Dialog.Trigger and Dialog.Close , which is to avoid declaring state, but it is more flexible and powerful than Dialog.Trigger and Dialog.Close.

s97712 avatar Apr 25 '24 03:04 s97712