1
Fork 0
This commit is contained in:
Tobias Berger 2022-02-04 11:55:18 +00:00 committed by GitHub
parent c3e79ef0c7
commit 3cc4cf2593
4 changed files with 21 additions and 11 deletions

View file

@ -1,14 +1,14 @@
import { FunctionComponent } from "react"; import React from "react";
type AuthorComponentProps = { type AuthorComponentProps = {
authorId: string; authorId: string;
authorNickname: string; authorNickname: string;
}; };
const AuthorComponent: FunctionComponent<AuthorComponentProps> = ({ const AuthorComponent = React.memo(function Author({
authorId, authorId,
authorNickname, authorNickname,
}) => { }: AuthorComponentProps) {
return ( return (
<span <span
className={ className={
@ -19,6 +19,6 @@ const AuthorComponent: FunctionComponent<AuthorComponentProps> = ({
{authorNickname} {authorNickname}
</span> </span>
); );
}; });
export default AuthorComponent; export default AuthorComponent;

View file

@ -1,4 +1,4 @@
import { useState } from "react"; import React, { useState } from "react";
import { ReadyState as WebSocketReadyState } from "react-use-websocket"; import { ReadyState as WebSocketReadyState } from "react-use-websocket";
export type ConnectionOptions = { export type ConnectionOptions = {
@ -11,7 +11,7 @@ export type ConnectComponentProps = {
webSocketReadyState: WebSocketReadyState; webSocketReadyState: WebSocketReadyState;
}; };
export default function Connect({ const Connect = React.memo(function Connect({
tryConnect, tryConnect,
webSocketReadyState, webSocketReadyState,
}: ConnectComponentProps): JSX.Element { }: ConnectComponentProps): JSX.Element {
@ -56,4 +56,5 @@ export default function Connect({
</button> </button>
</> </>
); );
} });
export default Connect;

View file

@ -1,3 +1,4 @@
import React from "react";
import { ConnectedUser } from "src/lib/ServerMessage"; import { ConnectedUser } from "src/lib/ServerMessage";
export type UserBarProps = { export type UserBarProps = {
@ -6,7 +7,7 @@ export type UserBarProps = {
getName(id: string): string; getName(id: string): string;
}; };
export default function UserBar({ const UserBar = React.memo(function UserBar({
connectedUsers, connectedUsers,
currentlyTyping, currentlyTyping,
getName, getName,
@ -31,4 +32,6 @@ export default function UserBar({
</ol> </ol>
</section> </section>
); );
} });
export default UserBar;

View file

@ -213,17 +213,23 @@ export default function Index(): JSX.Element {
<></> <></>
) : ( ) : (
<> <>
Your ID: <span style={{ fontWeight: "bold" }}>{authorId}</span> Your name:{" "}
<span title={authorId} style={{ fontWeight: "bold" }}>
{getName(authorId)}
</span>
</> </>
)}{" "} )}
<br />
<Connect <Connect
tryConnect={tryConnect} tryConnect={tryConnect}
webSocketReadyState={webSocket.readyState} webSocketReadyState={webSocket.readyState}
/> />
{/*
<span>Ready state: </span> <span>Ready state: </span>
<span style={{ fontWeight: "bold" }}> <span style={{ fontWeight: "bold" }}>
{WebSocketReadyState[webSocket.readyState]} ({webSocket.readyState}) {WebSocketReadyState[webSocket.readyState]} ({webSocket.readyState})
</span> </span>
*/}
</header> </header>
<div id="container"> <div id="container">
<section id="message-area"> <section id="message-area">