So I’ve started building a portfolio site for myself, gone with Astro as it’s now the cool new thing, so thought why not, was going to use Gatsby but this seems like the more performant solution and you have a lot of freedom with it (not tied in to a GQL CMS). As I understand it, Astro is a soluti…
Tag: reactjs
Counter inside an onClick function
I have a button that adds a new div (onClick). I want to add +1 to cargoNumberCounter so that it shows that it’s a new div. I thought I could make it work like I have shown in the example, or by spreading the state like so setCargoNumberCounter([…cargoNumberCounter, cargoNumberCounter +1]), but fo…
I’m having trouble figuring out the logic in my custom hook
Basically, as you can see in the code, I only want to run one of these API requests. If origCompId is passed, it runs duplicateInstance, otherwise, it runs addNewInstance. origCompId is a query parameter so it takes a second for it to update. This causes addNewInstance to run because origCompId begins as null…
Fetching data for another variable react
I have a question of something that looks pretty obvious but It’s getting hard for me. I know that for fetching data that will get actually rendered in a component you need to use reacthooks and useState. However I am having a problem because I need to fetch some data and then store it in a variable tha…
Adding Base URL in react.js project is not working
I want to add the base URL to my react.js project. However I had tried couple of methods that did not work. For example, if my project url is : It should appear in address bar as : Below is my project code. index.js App.js What I had tried? As I referred in stackoverflow and also many other websites, integrat…
How to add and remove multiple checkbox values and update nested array in React state hook
I am using React Context to create a multistep form, the form must keep the selection when the user clicks the next or previous step. I am using the below code and it’s working fine until I reach the stage to add multiple features using the checkbox, once items are checked, user can go to the previous s…
I can fetch data based on my query, but then the fetching never stops. How do I limit the fetch requests?
As I type in my search, the data will fetch from the API properly. The problem is that it keeps fetching several thousand times until the API throws an error. I successfully implemented an abortController, but I feel like there’s a less abrupt way to stop a fetch. I am using the useEffect hook based on …
React Search bar maps out every item instead of waiting for userInput
I am currently pulling data from an API that gives random user data like name, age, email, etc … I have setup a searchbar component and I map over the array but it returns all my names without waiting on a userInput. I am passing my state as props deconstructed as shown below. I also get no errors on my
react-dom-router Link component doesnt work as expected
I have a react app with two pages— the home and trip page. The trip page is rendered with the tripID passed in through the url. My app.js looks like : I have a global navbar with a menu of different tripIds as many Link to navigate to the TripComponent. When i am at the “/” path, and I navig…
How to make child components use map() from App.js props data?
My react is 18.2. I want the child component to receive data and use map() from App.js. I checked the child component received the data, but I don’t know why does it can’t use map(). It shows this error. Uncaught TypeError: Cannot read properties of undefined (reading ‘map’) So do anyo…