I am trying to call a function to fetch data from an api and display the data. However when I call this function, the page refreshes and state is reset so the page doesn’t display anything. In a child component, I have an input box and a form. OnSubmit, this form will save input to state (listOfNames) in the parent
Tag: use-effect
I’m confused about this statement, Object.entries
I’ve been watching the video, over and over again but I can’t seem to understand it properly, can somebody help me explain this line by line? I’ve get the point about “cat &&” but the rest confuses me. Answer Going through the above code line by line: I am assuming you have a state variable with a setter function setFilteredProducts
Data fetched and set with setState inside useeffect doesnt appear in console log unless i set a timeout
So I am fetching data from my database for each item in the array groups and then I want to map through this data (twice because it’s an array inside an array) in the jsx part of the component. The problem though is that the state is changed “too late” This is my guess because the console log doesn’t show
How to fix React.useEffect and useCallback circular loop when updating a state?
I’m fetching some data from an API, but since I am using this data to update a state within a useEffect, this state becomes a required dependency, which causes a circular loop. state is updated -> useEffect is called -> state is updated … I read a lot of answers and articles about that, but I couldn’t find an answer
useEffect doesn’t fire when data change
I created a table with filter. every thing worked well. Later on, I wanted to change the filters from material ui to Core ui. I created one filter and tried to test it before moving. But it didn’t work. The problem that useEffect doesn’t fire no matter what. I even tried to put variable x and increment it when a
Getting undefined props in functional react components
How to pass the {requests} prop to the RequestRow component after executing the setRequests? My understanding is that the requests get initialized as undefined in the beginning and before being set with the asynchronously called object, it gets passed to the RequestRow component as undefined, and the error occurs. The RequestRow component is shown below. It takes in the {requests}
Rendered more hooks than during the previous render REACT.js
I have an issue, I’m trying to set a value to a state (selectedPathway) regarding the another const (countryLabel) that is set via redux. Once “selectedPatway” is set, I would like to display the result in <Select value={selectedPathway} /> This Select is return by the main component that surround all the logic. Everything works well but when I refresh the
React API call in useEffect runs only when parameter is hardcoded, not when using state
Hi I am creating an app where a user can search for a book and put it on a shelf depending on which shelf the user clicks on. Currently the user can type a query and many results can get displayed. The user can open a dropdown on a book and click on a shelf (in the dropdown) to select
How can i loop object in useEffect React js
Here is my code! I want loop object in useEffect! I have a task to edit data! so for that I created a state and using useEffect I am taking data and showing values on input fields! but data I want to show that is images! and here is the JSON that I am taking! Here I need to loop
Why does addEventListener and removeEventListener inside useEffect() require an arrow function?
I’m trying to set onTop state to true if the user has scrolled to the top and false otherwise. I tried the following. The above example doesn’t work but throws no error either. Note that I added an arrow and braces to the second parameter function. The above example works as intended. Can anyone explain why? Thanks very much! Answer