Comments (9)
严格模式下的行为,确实和官网预期的不一样。看来严格模式下的单测有点问题
from hooks.
{ cacheKey: "cacheKey-share", staleTime: -1 }
from hooks.
Maybe you need to set it to not expire or staleTime
from hooks.
Maybe you need to set it to not expire or staleTime
it's wried. I used official example in the Preview, why to set staleTime in strict mode? @zhangmo8
from hooks.
I don't. But it's work.
from hooks.
@zhangmo8 actually, we are not on the same page. I need refresh the datas, but if I set staleTime to -1, the refresh is invalid.
from hooks.
ok. 我知道啦...英文描述比较麻烦...
它的行为是对的,或者说在预料之中的...
你设置的请求是3s,在这3s内,数据是已经被缓存下来的,所以当点击【更新】按钮的一瞬间,它会直接读取缓存的数据,并在请求完成(3s)后更新数据,我理解这是符合预期的。
你的问题其实是在于,非严格模式下,它两个数据是同步的,而严格模式下并没有同步更新,我认为它可能是react的render策略引起的问题
语言描述比较苍白,为此,我录制了一个视频来描述这个行为。并且更改了请求时间为5s,以便你能够更好的看到它读取缓存的数据
Screen.Recording.2024-04-24.at.11.00.37.mov
另外附上链接 Preview
from hooks.
你的问题其实是在于,非严格模式下,它两个数据是同步的,而严格模式下并没有同步更新,我认为它可能是react的render策略引起的问题
OK got it, 其实我想说的就是这个问题,如果开启StrictMode,就只能手动去refresh了
from hooks.
ok. 我知道啦...英文描述比较麻烦... 它的行为是对的,或者说在预料之中的... 你设置的请求是3s,在这3s内,数据是已经被缓存下来的,所以当点击【更新】按钮的一瞬间,它会直接读取缓存的数据,并在请求完成(3s)后更新数据,我理解这是符合预期的。
你的问题其实是在于,非严格模式下,它两个数据是同步的,而严格模式下并没有同步更新,我认为它可能是react的render策略引起的问题
语言描述比较苍白,为此,我录制了一个视频来描述这个行为。并且更改了请求时间为5s,以便你能够更好的看到它读取缓存的数据
Screen.Recording.2024-04-24.at.11.00.37.mov
另外附上链接 Preview
所以,感觉是应该去给 React 提交 issues,或者采用 抽离状态,memo等方式阻止它的更新,来保持和严格模式下的表现一致,以便你在开发环境的表现行为和打包后的表现行为一致。
当然,如果你是拉磨,我更推荐去除严格模式
from hooks.
Related Issues (20)
- useRequest 会考虑把 http status code 纳入处理过程么? HOT 1
- BUG useClickAway 不可用 HOT 6
- useWebSocket 没有提供重置latestMessage的方法 HOT 2
- useAntdTable 初始化请求执行2次 HOT 2
- useInViewport 弄一個triggerOnce的參數比較好 HOT 3
- [RFC] useEventBus HOT 7
- 能不能把useTimeout升级一下? HOT 9
- 官网白屏 HOT 1
- [RFC]useSwipeEvent
- 官网国内镜像打不开了 HOT 2
- runAsync 时能否重新指定options
- useLongPress在pc电脑外接触控评时,不触发
- useUrlState doesn't delete initialState when state is set to undefined
- Virtual List did not Load New Data Rows After Scroll HOT 1
- resetState的随机数问题
- useAntdTable在manual=true的情况下,defaultParam和手动run都不会填充表单默认值 HOT 4
- [bug] useResponsive 源码缺乏 default 导出,与 babel-plugin-import 配合时出错
- useIsomorphicLayoutEffect更名 HOT 1
- 版本3.8.0 useSelections 可以增加兜底 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hooks.