weixin_39986435
2021-01-12 19:45Memoize 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条回答
为你推荐
- 一旦用户登录,Laravel定制防护不起作用
- routes
- laravel
- php
- 2个回答
- CakePHP:在routes.php中重定向url
- routes
- php
- 1个回答
- 如何使用htaccess在codeigniter中重定向URL?
- routes
- url
- php
- 3个回答
- http路由url部分到不同的服务器
- routes
- wordpress
- php
- 1个回答
- PHP / MySQL定价路线
- routes
- mysql
- permutation
- php
- 1个回答
换一换