I'm new to react query and loving it so far. I get that it is mainly a UI library. So it's great for handling/displaying errors, loading states. But often I find myself wanting to wait for some specific action in an async way. So, I'd love to be able to wait for a promise to return before triggering an action e. g. a redirect.
Here is an example:
const NewPostForm = props => {
const history = useHistory();
const mutatePostInfo = useUpdatePost(); // useMutate hook
const [value, setValue] = useState("")
const handleSubmit = () => {
mutatePostInfo.mutate(value);
// I WANT TO: wait for the action to complete before redirecting
history.push("/new-route/")
}
return (
<form onSubmit={handleSubmit}>
<input value={value} onChange={(e) => setValue(e.target.value)} />
</form>
)
}