const Feedback = () => {
const [comment, setComment] = useState('');
const postCommentMutation = useMutation({
mutationFn: () => {
const postComment = async () => {
const payload = comment; // Why is this always an empty string?
return await myApi.postComment(payload);
};
return postComment();
},
});
return (
<>
<input value={comment} onChange={e => setComment(e.target.value)} />
<button
onClick={() => {
postCommentMutation.mutate();
setComment('');
}}
/>
</>
);
};
const Feedback = () => {
const [comment, setComment] = useState('');
const postCommentMutation = useMutation({
mutationFn: () => {
const postComment = async () => {
const payload = comment; // Why is this always an empty string?
return await myApi.postComment(payload);
};
return postComment();
},
});
return (
<>
<input value={comment} onChange={e => setComment(e.target.value)} />
<button
onClick={() => {
postCommentMutation.mutate();
setComment('');
}}
/>
</>
);
};