primitives
primitives copied to clipboard
[Dialog] Close the dialog after asynchronous form submission without declaring state
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>
)}/>
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.
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
.