mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 22:18:06 +01:00
3d46f47817
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
32 lines
695 B
TypeScript
32 lines
695 B
TypeScript
// This hook allows a component to signal that it's done rendering in a way that
|
|
// can be used by e.g. our embed code to determine correct iframe height
|
|
|
|
let renderSignalReceived = false;
|
|
|
|
type Callback = () => void;
|
|
|
|
let onInitialRender: Callback;
|
|
|
|
export const afterInitialRender = (callback: Callback) => {
|
|
if (renderSignalReceived) {
|
|
callback();
|
|
} else {
|
|
onInitialRender = callback;
|
|
}
|
|
};
|
|
|
|
export const useRenderSignal = () => {
|
|
return () => {
|
|
if (renderSignalReceived) {
|
|
return;
|
|
}
|
|
|
|
renderSignalReceived = true;
|
|
|
|
if (typeof onInitialRender !== 'undefined') {
|
|
window.requestAnimationFrame(() => {
|
|
onInitialRender();
|
|
});
|
|
}
|
|
};
|
|
};
|