-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
80 lines (74 loc) · 2.58 KB
/
Copy pathpage.tsx
File metadata and controls
80 lines (74 loc) · 2.58 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
70
71
72
73
74
75
76
77
78
79
80
'use client'
import { useEffect, useState } from "react";
import { writeToRedis, readFromRedis } from "./actions";
export default function Page() {
const [inputValue, setInputValue] = useState("");
const [name, setName] = useState("");
const handleButtonClick = async () => {
await writeToRedis(inputValue);
setInputValue("");
await fetchName();
};
const fetchName = async () => {
const nameFromRedis = await readFromRedis();
setName(nameFromRedis);
};
useEffect(() => {
fetchName();
}, []);
return (
<div style={{ maxWidth: "600px", margin: "0 auto", fontFamily: "Arial, sans-serif", textAlign: "center" }}>
<h1 style={{ color: "#333", marginBottom: "20px" }}>Redis Server Action</h1>
<p style={{ color: "#555", marginBottom: "20px" }}>
This is a simple example of a server action using Redis.
</p>
<p>
<input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
style={{
width: "80%",
padding: "10px",
fontSize: "16px",
marginBottom: "10px",
border: "1px solid #ccc",
borderRadius: "4px",
}}
maxLength={50}
placeholder="say hi"
/>
<button
onClick={handleButtonClick}
style={{
padding: "10px 20px",
fontSize: "16px",
backgroundColor: "#007BFF",
color: "#fff",
border: "none",
borderRadius: "4px",
cursor: "pointer",
marginLeft: "10px",
}}
>
Submit
</button>
</p>
{name && (
<div
style={{
marginTop: "20px",
padding: "10px",
backgroundColor: "#f8f9fa",
border: "1px solid #ddd",
borderRadius: "4px",
color: "#333",
fontSize: "18px",
}}
>
<strong>Stored Name:</strong> {name}
</div>
)}
</div>
);
}