Readme

🌐 Client Side code for the React example

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
81
82
83
84
85
86
87
88
89
90
91
/**
* @title React CSR Client in Val Town
* @description Client-side React application for a personal portfolio website.
*/
/** @jsxImportSource https://esm.sh/react */
import React, { useState, useEffect } from "https://esm.sh/react";
import ReactDOM from "https://esm.sh/react-dom";
import { BrowserRouter, Route, NavLink, Routes } from "https://esm.sh/react-router-dom";
import { personalData } from "https://esm.town/v/iamseeley/personalData";
const Navigation = () => (
<nav>
<NavLink to="/" className={({ isActive }) => (isActive ? 'active' : '')} end>Home</NavLink>
<NavLink to="/projects" className={({ isActive }) => (isActive ? 'active' : '')}>Projects</NavLink>
<NavLink to="/about" className={({ isActive }) => (isActive ? 'active' : '')}>About</NavLink>
</nav>
);
const HomePage = () => {
const [count, setCount] = useState(0);
useEffect(() => {
const timer = setInterval(() => {
setCount((prevCount) => prevCount + 1);
}, 1000);
return () => clearInterval(timer);
}, []);
return (
<div>
<h2>Welcome to My Portfolio</h2>
<p>{personalData.summary}</p>
<p><strong>This website is rendered client-side with React.</strong></p>
<p>Check out the <a target='_blank' href='https://www.val.town/v/iamseeley/reactClient'>client</a> and <a target='_blank' href='https://www.val.town/v/iamseeley/reactServer'>server</a> code and start building your own site!</p>
<p>You've been on this page for {count} seconds.</p>
</div>
);
};
const AboutPage = () => (
<div>
<h2>About Me</h2>
<p>{personalData.about}</p>
</div>
);
const ProjectsPage = () => (
<div>
<h2>My Projects</h2>
{personalData.projects.map((project, index) => (
<a className="projectLink" target="_blank" href={project.url}>
<div key={index} className="project">
<h3>{project.name}</h3>
<p>{project.description}</p>
</div>
</a>
))}
</div>
);
const App = () => (
<BrowserRouter>
<header>
<h1>{personalData.name}</h1>
<p>{personalData.label}</p>
</header>
<Navigation />
<main>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/about" element={<AboutPage />} />
<Route path="/projects" element={<ProjectsPage />} />
</Routes>
</main>
<footer>
<ul>
{personalData.profiles.map((profile, index) => (
<li key={index}>
<a href={profile.url} target="_blank" rel="noopener noreferrer">
{profile.network}
</a>
</li>
))}
</ul>
</footer>
</BrowserRouter>
);
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 27, 2024