Last active
January 6, 2026 10:40
-
-
Save CreeJee/3b803eebd4e50595b43c06dbcff6461d to your computer and use it in GitHub Desktop.
저는 radix가 싫어유...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // radix 기준 예시 | |
| const { chain, resolve } = useDefer(); | |
| return (<Dialog> | |
| <DialogContent onAnimationEnd={resolve}> | |
| {/*...이후 Dialog내용*/} | |
| <Button onClick={() => chain(onSubmit}}>설정</Button> | |
| </DialogContent> | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useInsertionEffect, useRef } from "react"; | |
| type PromiseHandlers = { | |
| onResolve: () => void; | |
| onReject?: () => void; | |
| } | |
| export const useDefer = () => { | |
| const resolveRef = useRef<() => void>(null); | |
| const rejectRef = useRef<() => void>(null); | |
| const promiseRef = useRef<Promise<void> | null>(null); | |
| useInsertionEffect(() => { | |
| promiseRef.current = new Promise((resolve, reject) => { | |
| resolveRef.current = () => resolve(undefined); | |
| rejectRef.current = () => reject(undefined); | |
| }); | |
| return () => { | |
| resolveRef.current = null; | |
| rejectRef.current = null; | |
| promiseRef.current = null; | |
| }; | |
| }, []); | |
| return { | |
| chain: (promiseHandlers: PromiseHandlers) => { | |
| promiseRef.current?.then(promiseHandlers.onResolve, promiseHandlers.onReject); | |
| }, | |
| resolve: () => resolveRef.current?.(), | |
| reject: () => rejectRef.current?.(), | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment