weixin_39986435
weixin_39986435
2021-01-12 19:45

Memoize routes and named routes

In RouterImpl, routes and namedRoutes are recalculated every render, but their values only change if Router's children change, which—on the fly—it never does.

Wrapping routes and namedRoutes in React 's useMemo hook removes the hassle of recalculating these two values every render.

NOTE: The way namedRoutes is defined, it technically does remember if it was called since it closes over a boolean that it sets, but this is maybe a more React-ish way of doing it?

该提问来源于开源项目:redwoodjs/redwood

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐

换一换