Code Monkey home page Code Monkey logo

react-auth's Introduction

Open in StackBlitz

Open in codesandbox

  1. 在 layout render 里处理请求,将导致其他状态改变引起 render, 而还未请求完毕时, 又重新发起一次, 在 loader 里没有多次请求, 但是也需要考虑登录时使用 replace 刷新页面 重新请求
 if (!gameListIsFetched) {
    fetchGameList()
  }

    useEffect(() => {
      fetchGameList()
  }, []) // mounted 时直接请求一次, 缺点 user 改变不会重新请求,登录使用 replace 来修复

  

所以直接使用 useSwr, 直接在 app.tsx[loader 不是 hook, 不能在里面使用 useSwr] 里,mounted 时 获取所有数据之后再渲染路由,配合登录后使用 replace刷新页面(或者不刷新,使用 mutate)

使用 provider 可以挂起请求? 整个应用的 before hook https://gist.github.com/samselikoff/ac8076c6c224786da23c9297567585cf

https://doichevkostia.dev/blog/authentication-store-with-zustand/

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.