-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.tsx
More file actions
60 lines (52 loc) · 1.45 KB
/
index.tsx
File metadata and controls
60 lines (52 loc) · 1.45 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
import React, { useState } from 'react';
import * as ReactDOM from 'react-dom';
import moment from 'moment';
import { DynamicoClient, FailedRegisterStrategy } from '@dynamico/core';
import { DynamicoProvider, dynamico, Status } from '@dynamico/react';
import { dependencies } from './package.json';
interface MyCompProps {
username: string;
}
const MyComp = dynamico<MyCompProps>('mycomp', {
// devMode: true,
// componentVersion: '1.1.2',
// getLatest: true,
fallback: ({ username, dynamicoStatus }) => (
<div>
Hey {username}, I'm currently {dynamicoStatus.currentStatus} with{' '}
{dynamicoStatus.error && dynamicoStatus.error.stack}...{' '}
</div>
)
});
const resolvers = {
react: React,
'react-dom': ReactDOM,
moment: moment
};
const dynamicoClient = new DynamicoClient({
url: '/api/components',
dependencies: {
versions: dependencies,
resolvers
},
cache: localStorage,
failedRegisterPolicy: {
retries: 3,
retryRate: 100,
strategy: FailedRegisterStrategy.Ignore
}
});
const App = () => {
const [visible, setVisible] = useState(true);
return (
<DynamicoProvider client={dynamicoClient}>
<input type="checkbox" checked={visible} onChange={() => setVisible(!visible)} /> show component
{visible && (
<MyComp username="Test">
<span>testSpan</span>
</MyComp>
)}
</DynamicoProvider>
);
};
ReactDOM.render(<App />, document.getElementById('root'));