I have the following:
interface Message {
message?: {
title?: string;
description?: string;
body?: string;
};
}
const [message, setMessage] = useState<Message>({
message: {
title: "",
description: "",
body: "",
},
});
and I'm trying to handle my form in this method where I fill the form with newly created values:
const handleMessageInput = (
event: React.ChangeEvent<HTMLInputElement>,
field: keyof Message
) => {
setMessage({
...message,
[field]: event.target.value,
});
};
<input
onChange={(e) => handleMessageInput(e, "title")}
ref={(node) => {
input = node;
}}
/>
<input
onChange={(e) => handleMessageInput(e, "body")}
ref={(node) => {
input = node;
}}
/>
<input
onChange={(e) => handleMessageInput(e, "description")}
ref={(node) => {
input = node;
}}
/>
but the problem is when I submit the form I dont get my values means my state is not updated with the created values, which I think I missed something within extracting the fields, also is there a way to avoid using ref for each field I have ? so any help ?
UPDATE:
