score:0
one problem i see is that you are not passing a function reference in onclick, but doing a function call instead:
<div classname="m-toggle" onclick={togglemenu()}>
either remove the parentheses after togglemenu:
<div classname="m-toggle" onclick={togglemenu}>
or pass it as an inline arrow function:
<div classname="m-toggle" onclick={() => togglemenu()}>
score:0
you are calling the togglemenu()
method during component render which you shouldn't do.
so when your component tries to render, it calls togglemenu
method and returns null for m-toggle query selector
. you can either bind function reference or use arrow function.
<div classname="m-toggle" onclick={togglemenu}>
or
<div classname="m-toggle" onclick={() => togglemenu()}>
score:0
several problems:
- react onclick expects a function but you are invoking
togglemenu
instead. it should beonclick={togglemenu}
oronclick={()=>togglemenu()}
- you should be managing the classname using state instead of using
document.queryselector()
and modifying the element yourself.
Source: stackoverflow.com
Related Query
- Document query selector returns undefined in react
- React Router 4 Match returns undefined
- React useContext returns undefined
- react ref and query selector all
- .env variable returns undefined in React JS app
- Dispatch Redux action after React Apollo query returns
- AsyncStorage.getItem returns undefined : React Native
- useParams hook returns undefined in react functional component
- Accessing Passport's req.user within React (ES6)? API call returns req.user as undefined
- Axios get request returns undefined for the first time in React
- React function returns undefined
- Fetching from API endpoint with React returns value undefined
- import returns undefined instead of react component while testing
- Promise.all() inside useEffect in react returns an array of undefined items
- React Query v3 useInfiniteQuery returns isLoading, isFetching always true and isFetchingNextPage always false
- Consuming from React Context returns Cannot read property 'map' of undefined
- React Apollo Testing is not working. Query data is always coming undefined
- fetching data with react hook returns undefined on nested obj properties
- React hook form setValue returns undefined with multi select (react-select)
- Why usePrevious returns undefined on first render - react hooks?
- React file upload returns undefined
- React context returns undefined
- className returns undefined with Mocha Enzyme & React CSS Modules
- React query infinite scroll pageParams is undefined
- Next props returns undefined React + Redux
- localStorage.getItem() react returning undefined before graphql query
- React setState of an object returns undefined
- React testing with Jest and Enzyme @react-google-maps/api returns TypeError: Cannot read property 'maps' of undefined
- React Query return undefined data while in network tab the data exists but it does not show on the page
- JS / React - Function returns undefined before finished
More Query from same tag
- A better way to handle async callbacks and rendering DOM
- React JS mapStateToProps
- React state cannot be changed
- Value not updating for Input inside ANTD Form.Item
- React JSON mapped data. Trying to pass a setState variable from mapped function will not get the latest state on render
- Replace/Change Redux state array with other array using immer
- How to Programmatically Scroll Drawer in Material UI React JS?
- Trying to loop through JSON file
- React.js toggle faq type style
- react useState enters infinite loop even thou variable is the same
- How do I work with Redux/React in Kotlin.js?
- React Hooks, setTimeOut to set State to false
- not able to use $pull (Mongoose) to remove an object in an array for a user model
- align divs to the right side of the window in react
- Adding properties to created Redux Store in Typescript
- Route doesn't work in react-router-dom in a nested structure
- React-Router Nested Routes not working
- In React how do I use a conditional with rendering?
- How to manipulate recursively nested elements in react
- map in reactjs is taking too much time to load
- Can't change class in React
- How to interpolate styles in React?
- Returning the base URL in React
- How come I cannot return data array in global context?
- how to make parent component pass prop to children only when button is clicked
- Are there any disadvantages to just passing the entire state to components from redux?
- HttpOnly cookie not being sent to api
- Unexpected keys, "length", "action", "location" etc in Redux when using connectedRouter
- ReactJS: updating props - turning a 17 object array of 2 key:value pairs into one with 3 key:value pairs
- JWT Token (Invalid token Specified)