Skip to content

Commit

Permalink
Merge pull request #359 from algorandfoundation/use-dialog-bug
Browse files Browse the repository at this point in the history
bug - wrap use-dialog-form open in a useCallback
  • Loading branch information
PatrickDinh authored Dec 4, 2024
2 parents 5fcd3ab + bf4e8ec commit 0b1c863
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/features/common/hooks/use-dialog-form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react'
import { useCallback, useState } from 'react'
import { Dialog, DialogContent, DialogHeader, DialogTitle, MediumSizeDialogBody } from '../components/dialog'
import { Description } from '@radix-ui/react-dialog'

Expand Down Expand Up @@ -48,14 +48,16 @@ export function useDialogForm<TDataIn, TDataOut>({ dialogHeader, dialogBody: Dia
</Dialog>
)

const open = useCallback((dialogData: TDataIn) => {
setIsOpen(true)
setDialogData(dialogData)
return new Promise<TDataOut | undefined>((resolve) => {
setResolvePromise(() => resolve)
})
}, [])

return {
open: (dialogData: TDataIn) => {
setIsOpen(true)
setDialogData(dialogData)
return new Promise<TDataOut | undefined>((resolve) => {
setResolvePromise(() => resolve)
})
},
open,
dialog,
}
}

0 comments on commit 0b1c863

Please sign in to comment.