question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What to do with react-router?

See original GitHub issue

Many times I have problem with <Link ... /> and <Route ... /> maybe with something like:

<Route
  path={`${match.url}/:player_id`}
  children={props => (
    <PlayerDetail {...props} teamId={match.params.team_id} />
  )}
/>
Route
whyDidYouRender.min.js:1185 {Route: ƒ} "Re-rendered because of props changes:"
whyDidYouRender.min.js:1190 props.children
whyDidYouRender.min.js:1190 different functions with the same name.
whyDidYouRender.min.js:1190 {prev children: ƒ} "!==" {next children: ƒ}

Can we make a Wiki page (or you have already planned a future article) just for react-router?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jmoyerscommented, May 24, 2019

It seems a lot of very commonly used packages aren’t built with memoization in mind. I guess it’s fine, premature optimization and all that. Same is true for many things that say they play nicely with hooks, but then return a new function on every call (e.g. react-apollo-hooks).

That being said, what I did with react-router was to, yes, acknowledge that the components behave like that, and 2. use the global exclude feature to reduce noise.

whyDidYouRender(React, {
  include: [/.*/],
  exclude: [/^Link/, /^Route/, /^BrowserRouter/]
});
1reaction
vzaidmancommented, May 24, 2019

Thats one way to go, but I still think this is not the right way to go. I think we should not usually care about why components render unless they are huge components that are bottlenecks and important to performance

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quick Start - React Router: Declarative Routing for React.js
To get started with React Router in a web app, you'll need a React web app. ... First, install create-react-app and make a...
Read more >
A Brief Overview of React Router and Client-Side Routing
React Router is an API for React applications. Most current code is written with React Router 3, although version 4 has been released....
Read more >
React Router - W3Schools
To add React Router in your application, run this in the terminal from the root ... If you are upgrading from v5, you...
Read more >
How To Handle Routing in React Apps with React Router
In React, routers help create and navigate between the different URLs that make up your web application. They allow your user to move ......
Read more >
Why Should You Use a Router in React.js? - Simplilearn
We will need to utilize Router in React JS to create a React application with navigation across multiple pages. React Router is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found