My first api request always fails after page load

I’m having a problem with my API request that always fails after page load. Don’t really know where Im wrong. Here’s my request and I call it when I interact with handleOpen function. const stock = {…

How to write a hook to load more button from fetching a json?

I am calling my fake api using fetch and getting Json data. How can I wire up my load more button so that it it loads more data? Everything works, I just need to add functionality to that load button. …

Invoking function expression

I’m following a React-hooks tutorial and I don’t understand why does the function expression, timerId in the top useEffect is being invoked automatically, but the function expression, search, in the …

FlatList scrollToIndex out of range

I have a FlatList where I’m trying to scroll through each index of my data array every X amount of seconds. There’s only two items in my array right now but there could be more. The current code works …

Using external script (in JavaScript) in Gatsby JS

I am trying to load a JavaScript code on my gatsby app. Inside my static folder on my root folder I created a code called script.js. Here’s the snippet inside: window.addEventListener(“scroll&…

How to update cart quantity if item already exist in Cart – reactjs?

in this code, instead of showing “The product has been added to cart.” alert message, I want to update cart quantity if item already exist in cart, please help me out. const addToCart = (id) …

Sibling component not re-rerendering on state change (using useEffect, useState and Context)

In my Main.js I create a first global state with a username and a list of users I’m following. Then, both the Wall component and FollowingSidebar render the list of follows and their messages (plus …

React functional component with mapped Child functional component with onClick function

Hi I have mapped some json data named “projectsData” and I am trying to “bind” an onClick event with a setState hook. The mapping works except for the “onClick” does not …

How to immediatelly update Parent state inside Child components

I’m trying to immediatelly update a parent components’ state so I can properly use it in a Child (nested) component. I will try to give as many details as possible so you an understand. So basically I …

How to update a state when a prop changes, without rendering twice

I have a data visualization component that has “width” as one of the props. A state keeps track of the zoom level in the chart, and it is updated when handling mouse events. The zoom needs …