Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

In my case (using Webpack) it was the difference between: import {MyComponent} from ‘../components/xyz.js’; vs import MyComponent from ‘../components/xyz.js’; The second one works while the first is causing the error. Or the opposite.

React-router URLs don’t work when refreshing or writing manually

Server-side vs Client-side The first big thing to understand about this is that there are now 2 places where the URL is interpreted, whereas there used to be only 1 in ‘the old days’. In the past, when life was simple, some user sent a request for http://example.com/about to the server, which inspected the path … Read more

Programmatically navigate using React router

React Router v5.1.0 with hooks There is a new useHistory hook in React Router >5.1.0 if you are using React >16.8.0 and functional components. import { useHistory } from “react-router-dom”; function HomeButton() { const history = useHistory(); function handleClick() { history.push(“/home”); } return ( <button type=”button” onClick={handleClick}> Go home </button> ); } React Router v4 … Read more