Improve usage of setState

This commit is contained in:
Franck Royer 2021-04-22 15:57:43 +10:00
parent 25e6b1cbd3
commit 4c8a243c51
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 3 additions and 8 deletions

View File

@ -17,21 +17,16 @@ interface Props {
lines: ChatMessage[],
}
interface State {
messageToSend: string
}
export default function Room (props :Props) {
let [state, setState] = useState<State>({ messageToSend: '' });
let [messageToSend, setMessageToSend] = useState<string>('');
const { waku } = useWaku();
const messageHandler = (msg: string) => {
setState({ messageToSend: msg });
setMessageToSend(msg);
}
const sendMessage = async () => {
const chatMessage = new ChatMessage(new Date(), 'web-chat', state.messageToSend);
const chatMessage = new ChatMessage(new Date(), 'web-chat', messageToSend);
const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), ChatContentTopic);
await waku!.relay.send(wakuMsg);
}