| 71 | }; |
| 72 | |
| 73 | const 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 | }; |