I am Developing MERN Stack Project. The problem is when I make the first API Call the first response is undefined and the map function gives an error ‘Map is not a function and it makes sense. the problem is i tried several approaches to prevent this from happening but it won’t work This is the Co…
Tag: reactjs
Conditional link styling React
I want my nav bar to style the page title I’m in, im using React and Tailwind CSS, for example, just make the title yellow when im on the selected path. My logic to achieve that would be this but isn’t working: My rout code: Nav bar code: Answer Well at the end the problem was the path variable wh…
How can I use the prevState in a state with multiple arguments?
You see, at this moment I am developing a showMorePost that I had previously done successfully, but this time I reformulated it by joining all the states that I had in one with several arguments The problem is that now instead of bringing me the posts that follow when calling the handleShowMorePosts, it gener…
How to useFetch with a for loop?
I am creating an application with react. I have to fetch several data. This is my fetch statement: At the end of the line, it is a 6 but I have this kind of problem. I have periods and these periods are changed for every object. I call the period from there and I find the length of periods like
Cannot POST / error when trying to create a checkout session with Stripe + React + Express
I am using Stripe’s pre-built checkout method to order and pay for products on my Reactjs app. I recently developed a basic shopping cart and now I am trying to create a “Go To Checkout” input form that would allow the user to send the products in the cart to my express server POST route whe…
Send order to children
Basically, as above, there is the Accordion components and a parent component that hosts all of them. Each Accordion component has a state called open. I want to change state of each child from parent component. How can I send an order to a child component to change its state? Answer Lift your state up into P…
React never ending loop in useEffect
Apologies. React noob here. Got an issue where my code has stuck on a never ending loop. I’ve stripped the code down only to the part I believe that’s causing the problem. I’ve used the useEffect method to match the componentDidMount. Is that correct? The moment I comment “setPackages(…
Adding an object conditionally inside an array
I want to add a conditional object inside an array of objects. If the condition is not met, I want it as if that object is not there AT ALL, while keeping the other objects as they are. Consider the following: //I tried doing the following but it doesn’t work Please Help.!!! Thanks for the help. Answer …
MUI5 not working with jest – SyntaxError: Cannot use import statement outside a module
Reproducible repo: https://github.com/hutber/cannotusestatement What is more worrying is: https://codesandbox.io/s/vigilant-bartik-bmz8x in the sandbox the tests pass. However if you checkout the above repo, which was imported into this sandbox it will not pass locally. I have no doubt that the issue is my je…
Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment …?
Here is my code: The error appears at the first character of the opening tag for the breakline HTML element. I do not understand why this is happening as I have code elsewhere that uses the same principle and has no errors at all. Answer These elements, inside the curly braces, need to be wrapped inside of a …