score:3
Accepted answer
the usegatracker
hook is being used outside the browserrouter
so there is no routing context above it in the reacttree.
to resolve, move the router to the component rendering app
so there's a provided routing context. this may likely be the index.js file. (you'd typically wrap app with the authprovider
here as well)
example:
... other imports ...
import { browserrouter as router } from 'react-router-dom';
import { authprovider } from "./context/authcontext"
const rootelement = document.getelementbyid("root");
reactdom.render(
<strictmode>
<authprovider>
<router>
<app />
</router>
</authprovider>
</strictmode>,
rootelement
);
...
const app = () => {
usegatracker(); // <-- has a routing context now!
return (
<>
<helmet>
<title>codingspace - learn by building web and mobile apps</title>
</helmet>
<div classname="relative grid min-h-screen md:grid-cols-layout-tablet xl:grid-cols-layout-desktop grid-rows-layout-desktop md:gap-6">
<navbar />
<sidebar />
<switch>
<suspense fallback={<div>loading..</div>}>
<route exact path="/" component={dashboard} />
</suspense>
</switch>
<feedback />
<footer />
</div>
</>
)
}
Source: stackoverflow.com
Related Query
- Cannot read properties of undefined (reading 'params') Uncaught TypeError whilte fetching data from JSON
- React Router: TypeError Cannot read properties of undefined (reading 'originalPositionFor')
- Uncaught TypeError: Cannot read properties of undefined (reading 'url')
- React, useRef not allowing to access current properties, getting Uncaught TypeError: Cannot read properties of undefined (reading 'clientHeight')
- Uncaught TypeError: Cannot read properties of undefined (reading 'button')
- Uncaught TypeError: Cannot read properties of undefined (reading 'location')
- React, getting Uncaught TypeError: Cannot read properties of undefined (reading 'map') on some refreshes
- Uncaught TypeError: Cannot read properties of undefined (reading 'map')
- NextJS: Uncaught TypeError: Cannot read properties of undefined (reading 'attributes')
- React, not able to consume value inside context, getting Uncaught TypeError: Cannot read properties of undefined
- Uncaught TypeError: Cannot read properties of undefined (reading 'img')
- React: Uncaught TypeError: Cannot read properties of undefined (reading 'recipe_name')
- Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'setState')
- Uncaught TypeError: Cannot read properties of undefined (reading 'start_time')
- Uncaught TypeError: Cannot read properties of undefined (reading 'images')
- Uncaught TypeError: Cannot read properties of undefined (reading 'length') in my react app
- Uncaught TypeError: Cannot read properties of undefined (reading 'length') while setting the state
- Error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'signin') in AuthService TypeScript
- Uncaught TypeError: Cannot read properties of undefined (reading 'source') react v16
- Problem while returning an array on react: Uncaught TypeError: Cannot read properties of undefined (reading 'items')
- React Router Error - Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'pathname')
- Getting constant error of - Uncaught TypeError: Cannot read properties of undefined (reading 'map')
- React Swiper: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'addClass')
- Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase') React - Redux
- Uncaught TypeError: Cannot read properties of undefined (reading 'push')
- Uncaught TypeError: Cannot read properties of undefined (reading 'roll')
- Uncaught TypeError: Cannot read properties of undefined (reading 'image') BookingCar.js
- Uncaught TypeError: Cannot read properties of undefined (reading 'pathname') : how to solve this router issue?
- Uncaught TypeError: Cannot read properties of undefined (reading 'pathname')
- Uncaught TypeError: Cannot read properties of undefined (reading '0')
More Query from same tag
- "Can't perform a React state update on an unmounted component" when i try to change state in useEffect()
- Why is my JSX rendering a <tr> when it shouldn't?
- OnChange in a map function with Hooks updates all fields
- ReactJS and bootstrap
- React: How to re-render a route on state change within App.js
- How to fix "Element type is invalid: expected a string ... but got: object" error in React
- Node can't connect to Redis via Docker Compose
- How can I call the function of a parent component inside of a child component?
- Can someone explain how this state update is resolved?
- Why Form Test Fails While Using React Hook Form?
- React Router not rendering page
- Cannot search for all three properties on mongoDB
- MapDispatchToProps doesn't work on returning an object
- How can i make my checkbox and input search to be inline?
- React component is making infinite API calls
- How to add href to a button in react material-ui stepper
- Unable to import module when using alias in package json
- How to read an object from an array that has only 0 index in javascript
- Toggling between an image grid and image slider with one array of images in react hooks
- If/else statement inside loop inside return statement?
- Attempted import error: 'Typography' is not exported from 'antd'
- How to make the footer always at the bottom
- Why there are indents in the table list?
- How to set a date string to a the following format
- how to add an Arrow icon inside my React Js Project
- State not changing after calling this.setState
- Cannot read property 'someFunction' of null for 'someFunction' within onClick
- react+redux reducer handling with null
- Jest - Unexpected token import
- @mui/material <Checkbox> with Formik