New frontend and tools

This commit is contained in:
2024-10-01 19:31:57 -04:00
parent b56619a2e6
commit 9d25dd7d94
15 changed files with 937 additions and 191 deletions

View File

@ -0,0 +1,23 @@
import { useState, useEffect } from 'react'
export default function useLocalStorage(key, initialValue) {
const [storedValue, setStoredValue] = useState(() => {
try {
const item = window.localStorage.getItem(key)
return item ? JSON.parse(item) : initialValue
} catch (error) {
console.log(error)
return initialValue
}
})
useEffect(() => {
try {
window.localStorage.setItem(key, JSON.stringify(storedValue))
} catch (error) {
console.log(error)
}
}, [key, storedValue])
return [storedValue, setStoredValue]
}

14
dewey/hooks/useSocket.ts Normal file
View File

@ -0,0 +1,14 @@
import { useEffect, useState } from 'react'
import io from 'socket.io-client'
export default function useSocket() {
const [socket, setSocket] = useState<any>(null)
useEffect(() => {
const newSocket = io('http://localhost:5001')
setSocket(newSocket)
return () => newSocket.close()
}, [])
return socket
}