How do I avoid ‘Function components cannot be given refs’ when using react-router-dom?

NavLink from react-router is a function component that is a specialized version of Link which exposes a innerRef prop for that purpose. You could’ve also searched our docs for react-router which leads you to https://mui.com/getting-started/faq/#how-do-i-use-react-router which links to https://mui.com/components/buttons/#third-party-routing-library. The last link provides a working example and also explains how this will likely change in … Read more

Uncaught Invariant Violation: Too many re-renders. React limits the number of renders to prevent an infinite loop

I suspect that the problem lies in the fact that you are calling your state setter immediately inside the function component body, which forces React to re-invoke your function again, with the same props, which ends up calling the state setter again, which triggers React to call your function again…. and so on. Instead, I … Read more