@attio/react-native-bottom-sheet-toolbox
Version:
37 lines (33 loc) • 1.1 kB
JavaScript
;
import { nanoid } from "nanoid";
import * as React from "react";
import { useBottomSheetActions } from "./use-bottom-sheet-actions";
// biome-ignore lint/suspicious/noExplicitAny: not useful to type
export function useBottomSheetCallbackAfterClose(callback) {
const [id] = React.useState(() => `useBottomSheetCallbackAfterClose:${nanoid()}`);
const {
close
} = useBottomSheetActions(id);
// biome-ignore lint/suspicious/noExplicitAny: not useful to type
const givenArgsRef = React.useRef(null);
const lastCallbackRef = React.useRef(callback);
lastCallbackRef.current = callback;
React.useEffect(() => {
return () => {
if (givenArgsRef.current === null) return;
if (givenArgsRef.current) {
lastCallbackRef.current(...givenArgsRef.current.args);
} else {
lastCallbackRef.current();
}
};
}, []);
// biome-ignore lint/suspicious/noExplicitAny: not useful to type
return (...args) => {
givenArgsRef.current = {
args
};
close();
};
}
//# sourceMappingURL=use-bottom-sheet-callback-after-close.js.map