MCPcopy Create free account
hub / github.com/primer/react / confirm

Function confirm

packages/react/src/ConfirmationDialog/ConfirmationDialog.tsx:153–177  ·  view source on GitHub ↗
(themeProps: ThemeProviderProps, options: ConfirmOptions)

Source from the content-addressed store, hash-verified

151let hostElement: Element | null = null
152export type ConfirmOptions = Omit<ConfirmationDialogProps, 'onClose'> & {content: React.ReactNode}
153async function confirm(themeProps: ThemeProviderProps, options: ConfirmOptions): Promise<boolean> {
154 const {content, ...confirmationDialogProps} = options
155 return new Promise(resolve => {
156 hostElement ||= document.createElement('div')
157 if (!hostElement.isConnected) document.body.append(hostElement)
158 const root = createRoot(hostElement)
159 const onClose: ConfirmationDialogProps['onClose'] = gesture => {
160 root.unmount()
161 if (gesture === 'confirm') {
162 resolve(true)
163 } else {
164 resolve(false)
165 }
166 }
167 root.render(
168 <ThemeProvider {...themeProps}>
169 <BaseStyles>
170 <ConfirmationDialog {...confirmationDialogProps} onClose={onClose}>
171 {content}
172 </ConfirmationDialog>
173 </BaseStyles>
174 </ThemeProvider>,
175 )
176 })
177}
178
179/**
180 * This hook takes no parameters and returns an `async` function, `confirm`. When `confirm`

Callers 4

ShorthandHookFunction · 0.85
useConfirmFunction · 0.85

Calls

no outgoing calls

Tested by 1