chore: migrate to reducer pattern instead of useState

This commit is contained in:
Alexander Daichendt 2025-02-12 11:33:48 +01:00
parent 18dd8b83f0
commit 7150ca87c3
7 changed files with 85 additions and 29 deletions

View file

@ -9,15 +9,15 @@ import { useChatState } from "../contexts/ChatContext";
function Room() {
const { roomId } = useParams();
const { isConnected, connect, sendMessage } = useWebSocket(roomId ?? "");
const { currentUser } = useChatState();
const { state } = useChatState();
return (
<Layout>
<section className="w-full">
<h2 className="text-xl bg-gray-100 p-4 flex justify-between items-center rounded-md shadow-sm">
<span className="font-medium">Room ID: {roomId}</span>
{currentUser && (
<span className="font-medium">User: {currentUser?.name}</span>
{state.currentUser && (
<span className="font-medium">User: {state.currentUser?.name}</span>
)}
<span
className={`px-3 py-1 rounded-full text-sm font-medium ${