Skip to content

Commit

Permalink
Remove alternative version of useAfterNextLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
mmocny committed Nov 23, 2023
1 parent 79ac656 commit 6534a53
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions sandbox/react-flushSync/hooks/useAfterNextLayout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useLayoutEffect, useRef, useState } from "react";
import { useLayoutEffect, useRef } from "react";

export function useAfterNextLayoutWithRefs() {
export function useAfterNextLayout() {
const callbacks = useRef([]);

useLayoutEffect(() => {
Expand All @@ -15,20 +15,4 @@ export function useAfterNextLayoutWithRefs() {
}
}

function useAfterNextLayoutWithState() {
const [callbacks, setCallbacks] = useState([]);

useLayoutEffect(() => {
if (callbacks.length === 0) return;
for (let callback of callbacks) {
callback();
}
setCallbacks([]);
}, [callbacks]);

return (callback) => {
setCallbacks((callbacks) => [...callbacks, callback]);
}
}

export { useAfterNextLayoutWithRefs as useAfterNextLayout };
export default useAfterNextLayout;

0 comments on commit 6534a53

Please sign in to comment.