Giter Site home page Giter Site logo

Comments (9)

liuyib avatar liuyib commented on June 3, 2024 2

严格模式下的行为,确实和官网预期的不一样。看来严格模式下的单测有点问题

from hooks.

zhangmo8 avatar zhangmo8 commented on June 3, 2024 1

{ cacheKey: "cacheKey-share", staleTime: -1 }

from hooks.

zhangmo8 avatar zhangmo8 commented on June 3, 2024

Maybe you need to set it to not expire or staleTime

from hooks.

fred8617 avatar fred8617 commented on June 3, 2024

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.

zhangmo8 avatar zhangmo8 commented on June 3, 2024

I don't. But it's work.

from hooks.

fred8617 avatar fred8617 commented on June 3, 2024

@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.

zhangmo8 avatar zhangmo8 commented on June 3, 2024

ok. 我知道啦...英文描述比较麻烦...
它的行为是对的,或者说在预料之中的...
你设置的请求是3s,在这3s内,数据是已经被缓存下来的,所以当点击【更新】按钮的一瞬间,它会直接读取缓存的数据,并在请求完成(3s)后更新数据,我理解这是符合预期的。

你的问题其实是在于,非严格模式下,它两个数据是同步的,而严格模式下并没有同步更新,我认为它可能是react的render策略引起的问题

语言描述比较苍白,为此,我录制了一个视频来描述这个行为。并且更改了请求时间为5s,以便你能够更好的看到它读取缓存的数据

Screen.Recording.2024-04-24.at.11.00.37.mov

另外附上链接 Preview

from hooks.

fred8617 avatar fred8617 commented on June 3, 2024

你的问题其实是在于,非严格模式下,它两个数据是同步的,而严格模式下并没有同步更新,我认为它可能是react的render策略引起的问题

OK got it, 其实我想说的就是这个问题,如果开启StrictMode,就只能手动去refresh了

from hooks.

zhangmo8 avatar zhangmo8 commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.