import { useCallback, useEffect, useRef } from "react";// The input bar where the user types messagesexport default function MessageInputBar({onMessage,}: {onMessage: (msg: string) => void;}) {const inputRef = useRef<HTMLInputElement>(null);const onKeyDown = useCallback((event: KeyboardEvent) => {// Focus the input when the user presses any key, to make interaction smootherinputRef.current.focus();// Invoke the passed callback when Entr is hit, then clear the messageif (event.key === "Enter") {const messageContent = inputRef.current?.value;if (messageContent) {onMessage(messageContent);inputRef.current.value = "";}}},[onMessage],);useEffect(() => {window.addEventListener("keydown", onKeyDown);return () => {window.removeEventListener("keydown", onKeyDown);};}, [onKeyDown]);return (<div className="flex"><divclassName="flex-1 flex p-2"style={{ backgroundColor: "var(--boost-light-grey)" }}><inputtype="text"className="flex-1 text-xl pl-4 pr-4 pt-2 pb-2 border-0 rounded-xl"placeholder="Type a message..."ref={inputRef}/></div></div>);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。