I am building a react js application with dummy backend using json-server.I am implementing a dropdown list but I am getting Cannot read property ‘map’ of undefined error on fetching from api.The api is working fine in browser but while fetching in react it is giving me this error. My component: M…
Tag: reactjs
React Unable to play audio
In my return statement of my react code I have: This creates a HTML object for the audio. I have a file called 49.mp3 in the same directory as my code. Then I have an event listener that plays that sound when a key is pressed: When I press my key, I know this function gets called but no audio
reactjs handle click outside an element error
I’m trying to create a function that will detect any click outside of an element. The error says: TypeError: Cannot read property ‘className’ of null The function works just fine when it only contains one of the conditions. Is there any problem with my code? I appreciate any kind of help. An…
How to use ReactTestUtils to Simulate onChange event to update State
I want to run unit tests on a simple score keeping component in React. My component has two State values, score and newPoints. An input element specifies the newPoints to add, and a button adds that to the score. Game.js: Problem: The component works fine in my browser but I can’t seem to get the unit t…
React: Rendered more hooks than during the previous render? React-spring
I’ve seen similar questions on SO about this error, but I haven’t been able to fix my problem below. The situation The code at this link works: https://codesandbox.io/s/frosty-water-118xp?file=/src/App.js However, what I don’t like about it is that I need to repeat myself in the ‘slide…
How can I use Bootstrap 5 with Next.js?
After installing bootstrap with npm install bootstrap I added the style to /pages/_app.js like so: However anything from it that uses javascript does not work at all, e.g. the Collapse example from their docs. If I add import ‘bootstrap/dist/js/bootstrap.js’ to /pages/_app.js then it starts “…
React Redux, trying to add products to cart
I am trying to add products to shopping cart by storing them in local storage but, they are not getting stored. I looked into Redux-dev-tools and found out my state is not updating: As you can see action is getting fired but my state is not updating: Here is the source code: cartAction.js cartReducer.js store…
Why open link is not working inside a async handler on iPad Safari?
Here is some strange things on opening _blank link programatically. Environment: Device: iPad 14 browser: Safari latest A button is handling async await operation, and then triggering open a link as _blank target. I am not sure why it is not working. Any suggestions are welcome! Answer Browsers tend to block …
React API call in useEffect runs only when parameter is hardcoded, not when using state
Hi I am creating an app where a user can search for a book and put it on a shelf depending on which shelf the user clicks on. Currently the user can type a query and many results can get displayed. The user can open a dropdown on a book and click on a shelf (in the dropdown) to select
How to use react.usememo using react and javascript?
i am doing some filtering on items based on ids which is in selection object. and then evaluating true or not based on its completion true or false from items which is an array of objects. below is my code, How can i put the block which includes noJobs calcualtion (from if(selection)) to React.useMemo. could …