我们在到处使用Next.js和react-query。我们要做的是设置一个全局查询,当对端点的调用由于访问令牌过期而失败时,它会刷新令牌并重新运行查询。
错误模式应该是用户被重定向到登录。在使用内置于react-query's的onError和重试设置方面,我们已经取得了很大的进展。
使用自定义函数,我们可以刷新令牌,然后再重试原始请求。但是,在再次尝试之后,我们希望将用户重定向到登录页面。为此,我们需要来自useRouter的Next,这是一个钩子。useQuery in react-query也是钩子。
有没有办法将这两者结合起来,这样我们就可以在onError of QueryC
我正在使用jest和@testing-library/react-hooks来测试用react-query实现的钩子,这些钩子在我的React本机代码中实现。
测试正常,但最后,我得到了:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHan
我从react-query库中看到了一个模式,它做了以下工作:
(OOP)
// it instantiates an object from a class
const queryClient = new QueryClient()
(钩子)
// Then it passes this object as a prop to the provider
<QueryClientProvider client={queryClient}>
<Todos />
</QueryClientProvider>
在<Todos />组件中,这个库为
好的,这个问题不是很精确,但是我想不出更好的方法来表达:react-查询不像预期的那样。我创建了一个尽可能接近文档的最小示例,以排除所有其他可能的错误来源。在这个示例中,我呈现两个组件,一个尝试使用react查询,另一个使用普通的旧useEffect和useState钩子。
import ReactDOM from 'react-dom/client';
//the import from react-query is where the first error appears: 'Could not find a declaration file for module