-
-
Notifications
You must be signed in to change notification settings - Fork 552
/
context.tsx
67 lines (61 loc) · 1.9 KB
/
context.tsx
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
// import { useState, createContext, useContext } from 'react';
// import { block } from 'million/react';
// const ThemeContext = createContext('light');
// const Context = block(({onClick}) => {
// const theme = useContext(ThemeContext);
// return (
// <button
// style={{
// color: theme === 'light' ? 'black' : 'white',
// backgroundColor: theme === 'light' ? 'white' : 'black',
// }}
// onClick={onClick}
// >
// {theme}
// </button>
// );
// });
// const App = block(() => {
// const [theme, setTheme] = useState('light');
// return (
// <div>
// <ThemeContext.Provider value={theme}>
// <Context onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')} />
// </ThemeContext.Provider>
// </div>
// );
// });
// export default App;
import { compiledBlock as _compiledBlock } from "million/react";
import { useState, createContext, useContext } from 'react';
import { block } from 'million/react';
const ThemeContext = createContext('light');
const Context_1 = _compiledBlock(_props => <button style={_props.v0} onClick={_props.v1}>
{_props.v2}
</button>, {
name: "Context_1",
portals: ["v2"]
});
const Context = ({
onClick
}) => {
const theme = useContext(ThemeContext);
return /*@million jsx-skip*/<Context_1 scoped v0={{
color: theme === 'light' ? 'black' : 'white',
backgroundColor: theme === 'light' ? 'white' : 'black'
}} v1={onClick} v2={theme} _hmr="1707395050534" />;
};
const App_1 = _compiledBlock(_props2 => <div>
{_props2.v0}
</div>, {
name: "App_1",
portals: ["v0"],
scoped: ["v0"],
});
const App = () => {
const [theme, setTheme] = useState('light');
return /*@million jsx-skip*/<App_1 v0={<ThemeContext.Provider value={theme}>
<Context onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')} />
</ThemeContext.Provider>} _hmr="1707395050536" />;
};
export default App;