I'm using Breeze - Laravel + React in default configuration. I have a problem with cleaning data from textarea after form submit.I know that maybe you don't remmember how Breeze's code look like so I show you below:
export default function SendMessage(props) {
const { data, setData, post, processing, errors } = useForm({
message: '',
});
const onHandleChange = (event) => {
setData(event.target.name, event.target.type === 'radio' ? data.permission = event.target.value : event.target.value);
}
const submit = (e) => {
e.preventDefault();
axios.post('/my-route', {
message: data.message,
}).then(() => {
data.message = '';
});
};
return(
<>
<ValidationErrors errors={errors} />
<form onSubmit={submit} mwthod="post">
<div className="mt-4">
<Label forInput="message" value="message" />
<Textarea
name="message"
value={data.message}
className="mt-1 block w-full"
autoComplete="message"
handleChange={onHandleChange}
required
/>
</div>
<div className="flex items-center justify-end mt-4">
<Button className="ml-4" processing={processing}>
Send
</Button>
</div>
</form>
</>
);
And Textarea look like this:
export default function Textarea({
name,
value,
className,
autoComplete,
required,
isFocused,
handleChange,
}) {
const input = useRef();
useEffect(() => {
if (isFocused) {
input.current.focus();
}
});
return (
<div className="flex flex-col items-start">
Value is {value}
<textarea
name={name}
className={
`border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm ` +
className
}
ref={input}
autoComplete={autoComplete}
required={required}
onChange={(e) => handleChange(e)}
>
{value}
</textarea>
</div>
);
}
As you can see I added Value is {value}. What is different, after I submit the form props value is cleaning what can I saw in this line. Problem is that it is further seen in textarea (props value doesn't disappear) and I don't have idea why. Could you help me?