-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConnector.tsx
More file actions
69 lines (62 loc) · 2.13 KB
/
Connector.tsx
File metadata and controls
69 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { useState } from "react";
import { CollectComponents } from "./CollectComponents";
import { SkyflowWrapper } from "./SkyflowWrapper";
import { Root, createRoot } from 'react-dom/client';
import RevealComponents from "./RevealComponents";
// Component to manage visibility state of Collect and Reveal forms
const ComponentWrapper: React.FC = () => {
// State hooks for toggling component visibility
const [showCollect, setShowCollect] = useState(false);
const [showReveal, setShowReveal] = useState(false);
return (
<div>
{/* Button container */}
<div style={{ marginBottom: '20px' }}>
{/* Toggle Collect form visibility */}
<button
onClick={() => setShowCollect(!showCollect)}
style={{ marginRight: '10px' }}
>
{showCollect ? 'Hide Collect' : 'Show Collect'}
</button>
{/* Toggle Reveal form visibility */}
<button
onClick={() => setShowReveal(!showReveal)}
>
{showReveal ? 'Hide Reveal' : 'Show Reveal'}
</button>
</div>
{/* Conditional rendering of components */}
{showCollect && <CollectComponents />}
{showReveal && <RevealComponents />}
</div>
);
};
// Class to handle React integration with Vue
export class ReactConnector {
// Store React root instance
private root: Root | null = null;
// Initialize React root with target DOM element
constructor(targetEl: HTMLElement) {
if (targetEl) {
this.root = createRoot(targetEl);
}
}
// Render React components with Skyflow context
render() {
if (this.root) {
this.root.render(
<SkyflowWrapper>
<ComponentWrapper />
</SkyflowWrapper>
);
}
}
// Cleanup method to prevent memory leaks
cleanup() {
if (this.root) {
this.root.unmount();
this.root = null;
}
}
}