Last active
June 27, 2021 00:23
-
-
Save Cerwyn/44a0120bf434875fb9aedf92352b2125 to your computer and use it in GitHub Desktop.
preact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { FunctionalComponent } from 'preact'; | |
| import { html } from 'htm/preact'; | |
| import { useEffect, useState } from "preact/hooks"; | |
| import style from './style.scss'; | |
| // Note: `user` comes from the URL, courtesy of our router | |
| const Profile: FunctionalComponent = (props: any) => { | |
| const { user } = props; | |
| const [time, setTime] = useState(Date.now()); | |
| const [count, setCount] = useState(10); | |
| useEffect(() => { | |
| let timer = setInterval(() => setTime(Date.now()), 1000); | |
| return () => clearInterval(timer); | |
| }, []); | |
| return html` | |
| <div class=${style.profile}> | |
| <h1>Profile: ${user}</h1> | |
| <p>This is the user profile for a user named ${user}.</p> | |
| <div>Current time: ${new Date(time).toLocaleString()}</div> | |
| <p> | |
| <button onClick=${() => setCount((count) => count + 1)}>Click Me</button> | |
| ${' '} | |
| Clicked ${count} times. | |
| </p> | |
| </div> | |
| `; | |
| } | |
| export default Profile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment