I’ve written a recursive function to find a given object and the path within that tree, but when I change the target id (over here : if(tree.targetModuleId === 7)) to 10 I got error: “message”: “Uncaught TypeError: Cannot read properties of undefined (reading ‘unshift’)R…
Tag: reactjs
Is eslint pre-commit hook in CRA bootstrapped application required?
My react application is bootstrapped using CRA(react-scripts v4.0.0) and I want to add a code formatter (prettier to be specific) that must format the code before committing the changes to my git repo. I know that eslint is a dependency of react-scripts and linting is done using ‘eslint-webpack-plugin'(…
Adding value to an array in useState but only at a particular index of the array
I have a piece of state which holds an array of comments. Each comment has an array of replies. How can I add a reply value to the replies array of a specific comment within the comments array? Here is my current attempt: idx holds the correct value I need but I do not think my implementation is correct here.
create image in React from backend dataURL
I’m trying to get a snapshot of HTML canvas like so: which seems to be working, and connected properly to the database. But I can’t figure out how to use the dataURL to create an image component on the React frontend I’m able to fetch them from the backend just fine and log the dataURL. I gu…
Different function gets passed to useEffect on every render? – ReactJS useEffect
I was going through useEffect from reactjs docs and I’ve found this statement here Experienced JavaScript developers might notice that the function passed to useEffect is going to be different on every render. We are passing a function to useEffect and this function is said to be different for each rend…
how to reverse a clicked list item onclick in reactjs
I am getting numbers from the input field and rendering them below the input field one by one with the click of the button. So I want to know how can I reverse a text for a particular clicked item from the list. Thank you. Answer Hey You want to do something like this for easie.
React custom hook Pagination “data” is not defined
I have got an API which displays categories of music on the browser and I am trying to create a custom hook for pagination, but I keep getting this error, object is not iterable. I am new to custom hooks and could really use some help. Can anyone shed some light on how to fix this? Custom hook Pagination comp…
React: Changed state in Child component. How to see the change in parent component?
For a website I am working on I have made a component with checkboxes that triggers a state change in a parent component. I have checked in the console through the child component that the state is changed, but I want the parent component to “notice” the change too. I have tried useEffect and comp…
How to sort or create a new array by grouping year and data
I need to sort this array of objects, in the format that gives me reading for the development of the layout below: I arrived at this code, but it’s still not enough for what I need, besides that I’m not using the best practices… here’s the code: Above also contains the array that I nee…
React Google Identity services
I have been trying to implement Google’s identity services API in my React app, but couldn’t get it to work. I’m trying to implement the following really simple JS code: https://developers.google.com/identity/gsi/web/guides/display-button#javascript What I came up with is the following: When…