MCPcopy
hub / github.com/mathuo/dockview / TestWrapper

Function TestWrapper

packages/dockview-react/src/__tests__/react.spec.tsx:73–109  ·  view source on GitHub ↗
(props: {
    component: React.FunctionComponent<TestInterface>;
    onReady: (api: ReactPart<TestInterface>) => void;
})

Source from the content-addressed store, hash-verified

71};
72
73const TestWrapper = (props: {
74 component: React.FunctionComponent<TestInterface>;
75 onReady: (api: ReactPart<TestInterface>) => void;
76}) => {
77 const [portal, setPortal] = React.useState<React.ReactPortal[]>([]);
78 const ref = React.useRef<HTMLDivElement>(null);
79
80 React.useEffect(() => {
81 const cut = new ReactPart<TestInterface>(
82 ref.current!,
83 {
84 addPortal: (portal: React.ReactPortal) => {
85 setPortal((_) => [..._, portal]);
86
87 return {
88 dispose: () => {
89 setPortal((_) => _.filter((_) => _ !== portal));
90 },
91 };
92 },
93 },
94 props.component,
95 {
96 valueA: 'stringA',
97 valueB: 42,
98 }
99 );
100
101 props.onReady(cut);
102
103 return () => {
104 cut.dispose();
105 };
106 }, []);
107
108 return <div ref={ref}>{portal}</div>;
109};

Callers

nothing calls this directly

Calls 2

disposeMethod · 0.95
onReadyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…