在我的多次尝试中,我尝试使用react-apollo-hooks和formik一起使用,但似乎不太可能。表单中的数据仅在<Formik>标记中可用,否则无法在其外部访问。此外,我不能同时调用我的useMutation钩子并将参数传递给它:
const SignUp = () => {
const classes = useStyles();
// The react-apollo-hook for useMutation
// Its not hard to call this, but it seems impossible to call it,
// w
我得到一个错误,最终崩溃了一个反应组件的测试。我使用阿波罗钩子突变useMutation和酶的成分发现通过id。
repo code\node_modules\react-dom\cjs\react-dom.development.js:154
var evt = document.createEvent('Event'); // Keeps track of whether the user-provided callback threw an error. We
^
TypeError: Cannot read
React查询中的突变最简单的情况是调用突变,然后使查询无效。
ReactQuery将在突变后重新获取背景中的数据,然后重新获取UI将与服务器状态保持一致。
这是使用ReactQuery时突变的“低挂果”:
import { useMutation, useQueryClient } from 'react-query'
const queryClient = useQueryClient()
// When this mutation succeeds, invalidate any queries with the `todos` or `reminders`
我第一次尝试react查询,然后在我的React应用程序开始时得到了这个。
尽管我在树的顶端添加了QueryClientProvider,但我仍然要面对:Error: No QueryClient set, use QueryClientProvider to set one
index.js
ReactDOM.render(
<QueryClientProvider queryClient={queryClient}>
<App />
</QueryClientProvider>
,
document.getElem
我正在编写一个CRUD应用程序,并使用React查询,我创建了一些自定义钩子,如下所述:
在文档中,我看到基本上有两种方法可以在发生突变后更新缓存:
() 查询失效
onSuccess: () => {
queryClient.invalidateQueries("posts");
}
手动更新缓存的()
// Update post example
// I get the updated post data for onSuccess
onSuccess: (data) => {
queryClient.setQueryData("posts