@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 29 lines 1.2 KB
Raw
1 import { useLayoutEffect } from "react";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import { render } from "../../test/render";
5 import { useStableCallback } from "./useStableCallback";
6
7 function Child({ value, onLayout }: { value: string; onLayout: (childValue: string) => void }) {
8 useLayoutEffect(() => {
9 onLayout(value);
10 }, [value, onLayout]);
11 return null;
12 }
13
14 function Parent({ value, seen }: { value: string; seen: string[] }) {
15 const read = useStableCallback((childValue: string) => seen.push(`${childValue}->${value}`));
16 return <Child value={value} onLayout={read} />;
17 }
18
19 describe("useStableCallback", () => {
20 // Child layout effects run before the parent's, so a position restore in a
21 // child must still reach the handler of the render it commits with.
22 it("calls the committing render's function from a child layout effect", async () => {
23 const seen: string[] = [];
24 // A plain hook test; a router would add its own commits around the rerender.
25 await using screen = await render(<Parent value="first" seen={seen} />, { router: false });
26 await screen.rerender(<Parent value="second" seen={seen} />);
27 expect(seen).toEqual(["first->first", "second->second"]);
28 });
29 });