File tree 1 file changed +57
-0
lines changed
src/py/reactpy/reactpy/samples
1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ from reactpy import component , html , run
2
+ from reactpy .core .hooks import use_state
3
+ from reactpy .backend .hooks import use_local_storage
4
+ from reactpy .core .types import LocalStorage
5
+
6
+ @component
7
+ def App ():
8
+ storage = use_local_storage ()
9
+ key_input , set_key_input = use_state ("" )
10
+ val_input , set_val_input = use_state ("" )
11
+
12
+ def handle_get (e ):
13
+ set_val_input (
14
+ storage .get_item (
15
+ key_input
16
+ )
17
+ )
18
+
19
+ async def handle_set (e ):
20
+ await storage .set_item (
21
+ key_input ,
22
+ val_input
23
+ )
24
+
25
+ return html .div (
26
+ html .h1 ("Local Storage" ),
27
+ html .input (
28
+ {
29
+ "type" : "text" ,
30
+ "placeholder" : "Key" ,
31
+ "value" : key_input ,
32
+ "on_change" : lambda e : set_key_input (e ["target" ]["value" ])
33
+ }
34
+ ),
35
+ html .textarea (
36
+ {
37
+ "placeholder" : "Value" ,
38
+ "value" : val_input ,
39
+ "on_change" : lambda e : set_val_input (e ["target" ]["value" ])
40
+ }
41
+ ),
42
+ html .button (
43
+ {
44
+ "on_click" : handle_get
45
+ },
46
+ "Get"
47
+ ),
48
+ html .button (
49
+ {
50
+ "on_click" : handle_set
51
+ },
52
+ "Set"
53
+ )
54
+ )
55
+
56
+
57
+ run (App )
You can’t perform that action at this time.
0 commit comments