This repository has been archived by the owner on Mar 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.tsx
65 lines (51 loc) · 1.61 KB
/
index.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
import { createApp, createStore, createGlobalState, createGlobalSignal } from 'solid-utils';
import { Router, Route } from 'solid-app-router';
import { Meta, MetaProvider, Title } from 'solid-meta';
const [globalState, setGlobalState] = createGlobalState({ name: 'Alexandre' });
const [globalSignal, setGlobalSignal] = createGlobalSignal(20);
const [Provider, useProvider] = createStore({
state: (props) => ({ count: props.count }),
actions: (set) => ({
inc: () => set('count', (c) => c + 1),
}),
effects: (_set, get) => [() => console.log(get.count)],
props: { count: 0 },
});
const Name = () => <h1>Watch me also change name here: {globalState.name}</h1>;
const Hoooome = () => {
const [state, actions] = useProvider();
return (
<>
<Title>Hello world!</Title>
<h1>
My name is: {globalState.name} and I'm: {globalSignal()}
</h1>
<Name />
<button
onClick={() => {
setGlobalState('name', (name) => (name === 'Alexandre' ? 'Alex' : 'Alexandre'));
setGlobalSignal(globalSignal() === 20 ? 22 : 20);
}}
>
Toggle name between 'Alex' and 'Alexandre' and my age between '22' and '20'
</button>
<hr />
<button onClick={actions.inc}>
Count from provider:{state.count} (open the console to see the effect)
</button>
</>
);
};
const App = () => (
<>
<Meta name="keywords" content="javascript solid ui framework" />
<Route />
</>
);
const routes = [
{
component: Hoooome,
path: '/',
},
];
createApp(App, {}).use(MetaProvider).use(Router, { routes }).use(Provider).mount('#app');