mirror of https://github.com/waku-org/js-waku.git
Improve usage of setState
This commit is contained in:
parent
25e6b1cbd3
commit
4c8a243c51
|
@ -17,21 +17,16 @@ interface Props {
|
||||||
lines: ChatMessage[],
|
lines: ChatMessage[],
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
|
||||||
messageToSend: string
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export default function Room (props :Props) {
|
export default function Room (props :Props) {
|
||||||
let [state, setState] = useState<State>({ messageToSend: '' });
|
let [messageToSend, setMessageToSend] = useState<string>('');
|
||||||
const { waku } = useWaku();
|
const { waku } = useWaku();
|
||||||
|
|
||||||
const messageHandler = (msg: string) => {
|
const messageHandler = (msg: string) => {
|
||||||
setState({ messageToSend: msg });
|
setMessageToSend(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMessage = async () => {
|
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);
|
const wakuMsg = WakuMessage.fromBytes(chatMessage.encode(), ChatContentTopic);
|
||||||
await waku!.relay.send(wakuMsg);
|
await waku!.relay.send(wakuMsg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue