调用函数组件体内外部的反应问题
因此,我一直在搜索Internet,以获取一个示例的示例,称为函数组件的主体外部。但是,我找不到样本。
我有一种查询类型的GraphQl,我正在等待我可以传递的形式的值。因此,我需要在Formik的Onsubmit函数中称其为。
我已经用
因此,这是我对查询的反应钩,
const [{ data, fetching, stale, error, extensions, operation }] = useForgotPasswordQuery({ variables: { email: "value from the form" } });
与突变不同,它返回一个函数,我可以在其中用来在功能之外调用。
const [, forgotPassword] = useForgotPasswordMutation();
...
<Formik initialValues={{ email: '' }} onSubmit={async (values, { setErrors }) => {
const response = await forgotPassword({ email: values.email });
}}>
我想在此用例中知道,我无法使用查询类型吗?否则这是我不知道的一种方式。
我已经在这里阅读 stackoverflow 这是约定:
查询 - 用于查询数据(选择操作)
突变 - 用于创建新的和更新/删除现有数据(插入,更新,删除)
以某种方式创建新的和更新/删除现有数据(插入,更新,删除),此公约对我来说很有意义,我想实现它。因此,我试图使用查询而不是突变来做到这一点。
So, I've been searching the internet for an example of a react-query function called outside the body of the function component; however, I was unable to find a sample.
I have a query type of GraphQL, and I am waiting for a value from the form that I could pass on. So I needed to call it inside the onSubmit function of Formik.
I have generated my hooks with GraphQL Codegen. Since we cannot call the react-hooks outside the function, I am uncertain how I can do this.
So, this is my react-hook for the query
const [{ data, fetching, stale, error, extensions, operation }] = useForgotPasswordQuery({ variables: { email: "value from the form" } });
Unlike with the mutation, it returns a function wherein I could use to call outside the function.
const [, forgotPassword] = useForgotPasswordMutation();
...
<Formik initialValues={{ email: '' }} onSubmit={async (values, { setErrors }) => {
const response = await forgotPassword({ email: values.email });
}}>
I'd like to know on this use case, I cannot use query type? Or this is a way that I am unaware.
I've read here in the Stackoverflow that the convention:
Query — for querying data (SELECT operations)
Mutation — for creating new and updating/deleting existing data (INSERT, UPDATE, DELETE)
In a way, this convention makes sense to me and I want to implement it. So I am trying to do it using the query rather than the mutation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论