dissidua/app/page.tsx
Eli Ribble b7100cd59d Add basic reading/writing of a name to localStorage.
That's where we will keep all of our settings.
2023-12-18 09:57:57 -07:00

29 lines
727 B
TypeScript

"use client"
import { useEffect, useId, useState } from "react";
export default function Home() {
const id = useId()
const [name, setName] = useState<string>('');
useEffect(() => {
if (typeof window !== "undefined" && window.localStorage) {
let name = localStorage.getItem("name");
console.log("Got name", name);
setName(name);
}
}, []);
function saveName(name: string) {
setName(name);
if (typeof window !== "undefined" && window.localStorage) {
localStorage.setItem("name", name);
}
}
return (
<main className="flex" >
<label htmlFor={id}>Name</label>
<input id={id} value={name} onInput={e => saveName(e.target.value)}></input>
</main>
)
}