The problem I’m facing here was, whenever I fetch the data with a button click (the button that leads to this route), the data will be fetch successfully, but whenever I input the link address directly myself in the browser, It keeps returning empty string when i console.log the data (Like this <empt…
Tag: reactjs
How to add the option to allow only one space in a regex
I want a regex that will allow only one space within a set of characters. I have the below regex which doesn’t accept space. The below regex only supports strings like 1. @alia 2. @ranbir 3. @shilpa I want a regex that will allow strings like 1. @alia bhat 2. @ranbir kapoor 3. @shilpa shetty Answer You …
How to add “`Context“` with routes set up?
I want to add the searchContext context in my App.js so that my Navbar an Results components have access to the variables in it. How would I do this with my routes set up? I tried to just add with with them but that didn’t work. This is the code. Edit: Added “// Another route that has nothing to d…
Firefox stops receiving responses after some HTTP requests (React + Axios, Node.js backend), sends only OPTIONS
As the title says, this only happens in Firefox. After some time the browser only sends OPTIONS requests with no responses, no status, no headers, nothing I can see in the debug console. All of this works perfectly under Chrome, Safari and Edge. I’ve already set up CORS middleware and headers within Nod…
Why my if statement is not working while the condition is true?
I am trying to create dynamic fields based on my selected attributes. I have 2 array objects addAttributes and fakeAttributes. fakeAttributes are the details of selected attributes. I have a dropdown select component if I pass the addAttributes it will show the data. If I select any option from my select comp…
How to get value from one component to another page/component without navigation?
I have a navbar component in which there is an input search bar. Currently I am taking the value of the search bar and navigate to the Results component and access the input value useParams. I have the let [ result, setResult ] = useState([]); in my Results component because the results can change after the s…
Typecsript and NextJS how to check if “document” exists
NextJS renders part of the code server-side. I can handle that. But I would need to check if cookies are set and here I run into problems. I tried: !!document && !!document.cookie and document !== undefined && !!document.cookie Each time I get the same error: ReferenceError: document is not de…
Remix useSubmit arbitrary data
I am trying to submit a form using Remix’s useSubmit hook. But I want to be able to pass arbitrary data along with my form submit data. I have form elements with some static values that have disabled/readonly attributes, which means their value will be null on form submission. However I have access to t…
useState is not re-rendering with push and pop on an array state
I’m attempting to update the usersData variable created using useState so that anytime someone clicks on add user, a data object is added to the beginning of usersData, but the problem is that it only works with spread operators and not with push, pop, or unshift operations, as seen in the code below. T…
I want to change the image I am using whenever the product is added to cart
I am using this right now, need to add a condition in such a way that whenever the getCartCount is 0 it should show image as bag_empty instead of bag and when the cart count is more than 0 it should show bag Answer You could use a ternary operator like below, assuming that you have your empty bag image