Answer First Solution use j?.tagName.toLowerCase() instead of j.tagName.toLowerCase() ?. is the Optional Chaining concept in JavaScript for more information you can check these links: reference JavaScript Optional Chaining Second Solution also if you don’t want to use ?., you must add some expressions i…
Tag: reactjs
useEffect debounce search technique
i’m trying to implement search functionality but i don’t want to call the api every time i type something . here is the code: Answer you can use the setTimeout() function and clearTimeout in the cleanup function and the useRef hook to get the previous state to call the API only once :
Run set interval when click from another component React
i want to trigger countdown of 60 seconds when user click from another component . so far i didn’t find any solution it is not working i search a lot but did not find.Thanks Answer Remember to clear your interval
React, getting Error: Invalid hook call. Hooks can only be called inside of the body of a function component
Can anyone help me with React Hooks basics, I am relatively new and couldn’t find proper help online I get error on const navigate = useNavigate() saying: Answer What they want for useNavigate (and all hooks) is to be called only at the top level of a React component or a custom hook. Don’t call Hooks i…
Unable to check all 3 conditions and return them in JS
I have a method that checks a con variable as true or false and return a device tag for each device, I could only get the first tag even though the 2nd, 3rd condition is true. How to check all the conditions and return all the devices. Answer As soon as you make a return, the function stops, everything after
Double nested Array in JSON leads to TypeError: Cannot read properties of null (reading ‘map’)
In my code I try to get to the 2 thumbnail urls in the JSON below. I’m only able to get in the first Array the but I’m not able to get in the second array the I am getting the error: Code JSON: Can anybody help a total JS newbie on this? Answer Look at your data. Most of
Child component not re-rendering with updated props
I have a child component, it looks through and creates Canvas elements in the DOM, then useEffect() draws things to these Canvases: And it’s parent component: When the suer clicks on the Dropdown, I pass the value back up to the parent component (Workspace). This then updates the Workspace state, and I …
Make state related index make true while other state always false
this is my function to make related state true I need to make index related state true while at the same time states not equal to index need make false, How can I achieve that in the same function above as a example – in current condition, if I expand (index 1), then expand (index 2) my array looks like
Next.js keeps throwing error params is undefined
I have successfully connected my custom server using Node.js and Express.js with Next.js. I’m trying to fetch a car by its id whenever I click it among other cars, so I can have that particular car only. But I keep getting an error saying params is undefined even though I get the id at the back of my li…
React blank page when I try to import from another component
The react app was working perfectly until I tried to import AlertDialogSlide from confirmation.js component. There are no errors while compiling but I have a blank page. Answer check out your confirmation.js file. Maybe you make some mistake on that. I run this code after commenting confirmation.js file, it&#…