App.js
import logo from './logo.svg';
import './App.css';
import Header from './componentes/Header';
import FormularioLogin from './componentes/FormularioLogin';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import Menu from './pages/Menu';
const router = createBrowserRouter([
{ path: 'menu', Component: <Menu /> },
{ path: '/', Component: <App /> },
])
function App() {
return <RouterProvider router={router} />;
}
export default App;
Menu.js
export default function Menu() {
return (
<div>teste</div>
)
}
The app as created with create-react-app
Complete error
Uncaught runtime errors: ERROR dispatcher is null useState@http://localhost:3000/static/js/bundle.js:35452:7 RouterProvider@http://localhost:3000/static/js/bundle.js:31433:66 renderWithHooks@http://localhost:3000/static/js/bundle.js:56085:31 mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:60056:17 beginWork@http://localhost:3000/static/js/bundle.js:61359:20 callCallback@http://localhost:3000/static/js/bundle.js:46341:18 invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:46385:20 invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:46442:35 beginWork$1@http://localhost:3000/static/js/bundle.js:66340:32 performUnitOfWork@http://localhost:3000/static/js/bundle.js:65588:16 workLoopSync@http://localhost:3000/static/js/bundle.js:65511:26 renderRootSync@http://localhost:3000/static/js/bundle.js:65484:11 performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:64879:78 workLoop@http://localhost:3000/static/js/bundle.js:72919:46 flushWork@http://localhost:3000/static/js/bundle.js:72897:18 performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:73134:25 ERROR dispatcher is null useState@http://localhost:3000/static/js/bundle.js:35452:7 RouterProvider@http://localhost:3000/static/js/bundle.js:31433:66 renderWithHooks@http://localhost:3000/static/js/bundle.js:56085:31 mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:60056:17 beginWork@http://localhost:3000/static/js/bundle.js:61359:20 callCallback@http://localhost:3000/static/js/bundle.js:46341:18 invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:46385:20 invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:46442:35 beginWork$1@http://localhost:3000/static/js/bundle.js:66340:32 performUnitOfWork@http://localhost:3000/static/js/bundle.js:65588:16 workLoopSync@http://localhost:3000/static/js/bundle.js:65511:26 renderRootSync@http://localhost:3000/static/js/bundle.js:65484:11 performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:64879:78 workLoop@http://localhost:3000/static/js/bundle.js:72919:46 flushWork@http://localhost:3000/static/js/bundle.js:72897:18 performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:73134:25 ERROR dispatcher is null useState@http://localhost:3000/static/js/bundle.js:35452:7 RouterProvider@http://localhost:3000/static/js/bundle.js:31433:66 renderWithHooks@http://localhost:3000/static/js/bundle.js:56085:31 mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:60056:17 beginWork@http://localhost:3000/static/js/bundle.js:61359:20 callCallback@http://localhost:3000/static/js/bundle.js:46341:18 invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:46385:20 invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:46442:35 beginWork$1@http://localhost:3000/static/js/bundle.js:66340:32 performUnitOfWork@http://localhost:3000/static/js/bundle.js:65588:16 workLoopSync@http://localhost:3000/static/js/bundle.js:65511:26 renderRootSync@http://localhost:3000/static/js/bundle.js:65484:11 recoverFromConcurrentError@http://localhost:3000/static/js/bundle.js:64976:38 performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:64889:26 workLoop@http://localhost:3000/static/js/bundle.js:72919:46 flushWork@http://localhost:3000/static/js/bundle.js:72897:18 performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:73134:25 ERROR dispatcher is null useState@http://localhost:3000/static/js/bundle.js:35452:7 RouterProvider@http://localhost:3000/static/js/bundle.js:31433:66 renderWithHooks@http://localhost:3000/static/js/bundle.js:56085:31 mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:60056:17 beginWork@http://localhost:3000/static/js/bundle.js:61359:20 callCallback@http://localhost:3000/static/js/bundle.js:46341:18 invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:46385:20 invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:46442:35 beginWork$1@http://localhost:3000/static/js/bundle.js:66340:32 performUnitOfWork@http://localhost:3000/static/js/bundle.js:65588:16 workLoopSync@http://localhost:3000/static/js/bundle.js:65511:26 renderRootSync@http://localhost:3000/static/js/bundle.js:65484:11 performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:64879:78 workLoop@http://localhost:3000/static/js/bundle.js:72919:46 flushWork@http://localhost:3000/static/js/bundle.js:72897:18 performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:73134:25 ERROR dispatcher is null useState@http://localhost:3000/static/js/bundle.js:35452:7 RouterProvider@http://localhost:3000/static/js/bundle.js:31433:66 renderWithHooks@http://localhost:3000/static/js/bundle.js:56085:31 mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:60056:17 beginWork@http://localhost:3000/static/js/bundle.js:61359:20 callCallback@http://localhost:3000/static/js/bundle.js:46341:18 invokeGuardedCallbackDev@http://localhost:3000/static/js/bundle.js:46385:20 invokeGuardedCallback@http://localhost:3000/static/js/bundle.js:46442:35 beginWork$1@http://localhost:3000/static/js/bundle.js:66340:32 performUnitOfWork@http://localhost:3000/static/js/bundle.js:65588:16 workLoopSync@http://localhost:3000/static/js/bundle.js:65511:26 renderRootSync@http://localhost:3000/static/js/bundle.js:65484:11 recoverFromConcurrentError@http://localhost:3000/static/js/bundle.js:64976:38 performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:64889:26 workLoop@http://localhost:3000/static/js/bundle.js:72919:46 flushWork@http://localhost:3000/static/js/bundle.js:72897:18 performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:73134:25 ERROR dispatcher is null useState@http://localhost:3000/static/js/bundle.js:35452:7 RouterProvider@http://localhost:3000/static/js/bundle.js:31433:66 renderWithHooks@http://localhost:3000/static/js/bundle.js:56085:31 mountIndeterminateComponent@http://localhost:3000/static/js/bundle.js:60056:17 beginWork@http://localhost:3000/static/js/bundle.js:61359:20 beginWork$1@http://localhost:3000/static/js/bundle.js:66318:18 performUnitOfWork@http://localhost:3000/static/js/bundle.js:65588:16 workLoopSync@http://localhost:3000/static/js/bundle.js:65511:26 renderRootSync@http://localhost:3000/static/js/bundle.js:65484:11 recoverFromConcurrentError@http://localhost:3000/static/js/bundle.js:64976:38 performConcurrentWorkOnRoot@http://localhost:3000/static/js/bundle.js:64889:26 workLoop@http://localhost:3000/static/js/bundle.js:72919:46 flushWork@http://localhost:3000/static/js/bundle.js:72897:18 performWorkUntilDeadline@http://localhost:3000/static/js/bundle.js:73134:25
2
Answers
Issue
The
App
component is recursively rendering itself.Don’t do this since there is no base case to end the recursion,
App
never gets a complete JSX value to render returned to it. You have effectively created a form of infinite render-looping.Solution
Remove the root
"/"
route renderingApp
, or render anything else other thanApp
.Examples:
It seems like there’s an issue with how you’re implementing routing in your React application. The error message "dispatcher is null" suggests that there might be a problem with the way you’re setting up your router.
The code you’ve provided seems to be attempting to use
createBrowserRouter
fromreact-router-dom
, but it’s not being used in the correct way. Here’s how you can fix it:Import BrowserRouter: First, import
BrowserRouter
fromreact-router-dom
instead ofcreateBrowserRouter
.Wrap Your App Component with BrowserRouter: Wrap your
App
component insideBrowserRouter
in yourindex.js
file, which is typically the entry point of your React application.Here’s how you can update your code:
And in your
App.js
, you don’t need to create a router manually. You can just return the components you want to render:Make sure you have the correct imports for
BrowserRouter
,Route
, andSwitch
from'react-router-dom'
.This setup should resolve the "dispatcher is null" error and correctly implement routing in your React application.