Skip to content

Commit

Permalink
fix: prevent errors when typing in NewChat component (#2879)
Browse files Browse the repository at this point in the history
Set initial message to empty string to prevent it from initializing as undefined
Set the chatName to an empty string
Refactor the callback messages with minimal types
  • Loading branch information
musale authored Nov 28, 2023
1 parent 7181efd commit 48d2d55
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions packages/mgt-chat/src/components/NewChat/NewChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,16 @@ const NewChat: FC<NewChatProps> = ({ mode = 'auto', onChatCreated, onCancelClick
[mode]
);
// chat name data control
const [chatName, setChatName] = useState<string>();
const onChatNameChanged = useCallback(
(_: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, data: InputOnChangeData) => {
setChatName(data.value);
},
[]
);
const [chatName, setChatName] = useState<string>('');
const onChatNameChanged = useCallback((_: React.FormEvent<HTMLInputElement>, data: InputOnChangeData) => {
setChatName(data.value);
}, []);

// initial message data control
const [initialMessage, setInitialMessage] = useState<string>();
const onInitialMessageChange = useCallback(
(event: React.FormEvent<HTMLTextAreaElement>, data: TextareaOnChangeData) => {
setInitialMessage(data.value);
},
[]
);
const [initialMessage, setInitialMessage] = useState<string>('');
const onInitialMessageChange = useCallback((_: React.FormEvent<HTMLTextAreaElement>, data: TextareaOnChangeData) => {
setInitialMessage(data.value);
}, []);
const createChat = useCallback(() => {
const graphClient: IGraph = graph('mgt-new-chat');
setState('creating chat');
Expand Down

0 comments on commit 48d2d55

Please sign in to comment.