use-effect Questions
2
Solved
I am trying to use useEffect and useRef() to get the latest value of my counter as well as compare to the previous value so that I know if I need to call the addValues or removeValues function.
I f...
Quittance asked 12/7, 2022 at 16:47
6
I thought useEffect is called once only after render, but it's being executed multiple times and not in the order I expected.
I expected it to msg 'data loading' while the fetch is in progress and ...
Bacteria asked 29/6, 2020 at 4:6
5
I am trying to use useEffect() in my react hook to update the state when my props change. but there is a delay and the useEffect is only firing after I click again on an element in my hook. Im fair...
Caravel asked 4/9, 2019 at 12:46
4
Solved
Is it good practice to use IIFE in useEffect or I should declare async function and then call it?
useEffect(() => {
(async () => {
const response = await fetch(
"https://jsonplacehol...
Remorseful asked 15/3, 2022 at 10:16
4
I know the conventional way when using hooks is to fetch the data using the useEffect hook. But why can't I just call axios in the functional component instead of a hook and then set the data.
Bas...
Undertow asked 27/5, 2020 at 19:6
4
Solved
This is a component that render data from firebase storage and make it listed. What the function has to do is set the videos extracted from firebase storage to the useState. That way I can call vid...
Microscopy asked 12/4, 2022 at 18:54
3
Solved
So I have the following situation when using a useEffect that calls a functions that depends on state.
Example:
// INSIDE APP COMPONENT
const [someState, setSomeState] = React.useState(0);
const...
Communalize asked 2/7, 2019 at 10:16
6
Solved
Like the title says, the localStorage I set registers the changes made to the todoList array and JSON.stringifys it; however, whenever I refresh the page the array returns to the default [] state.
...
Hedvig asked 12/5, 2022 at 22:34
4
I started learning to react and came across the code snippet where the function was passed as a dependency array in useEffect. I want to know the use case where such function is being passed as the...
Rosales asked 10/4, 2022 at 7:59
9
Solved
Re-posting a similar question to my last because of a new issue. I'm trying to use context with hooks to manage authentication in my react app. I'm getting the error TypeError: Cannot destructure p...
Sheepherder asked 14/6, 2020 at 22:8
3
Solved
Why is an infinite loop created when I pass a function expression into the useEffect dependency array? The function expression does not alter the component state, it only references it.
// componen...
Mossman asked 26/6, 2020 at 19:21
4
When I upgraded nextjs application from 9 to 12. There were some errors shown, that were not being taken take care of in previous version. One of them was: typeError: destroy is not a function
In t...
Horntail asked 19/5, 2022 at 14:30
3
Solved
I am attempting to pass an object through props to a child component. The value is set in the useEffect hook and lost when passed to my child component.
I have tried setting the value of the obje...
Curtice asked 15/5, 2019 at 18:53
18
Solved
The useEffect React hook will run the passed-in function on every change. This can be optimized to let it call only when the desired properties change.
What if I want to call an initialization func...
Filtrate asked 2/11, 2018 at 14:58
5
Solved
I gather that the useEffect Hook is run after every render, if provided with an empty dependency array:
useEffect(() => {
performSideEffect();
}, []);
But what's the difference between that,...
Teammate asked 27/10, 2019 at 12:28
3
Solved
I am new to React hooks and I am not sure how to achieve following goal. Let's say I have state1 and state2, and I use useEffect hook to call asyncFn1 and update state1.
Now I want to wait for stat...
Berardo asked 25/4, 2021 at 7:1
3
I am trying to test App.jsx
import getUserInfo from './services/user';
const App = () => {
const [isLoading, setIsLoading] = useState(true);
const [user, setUser] = useState({
firstName: 'F...
Monsour asked 1/11, 2021 at 21:7
2
If I return a function from useEffect I can be sure that that function will run when a component unmounts. But React seems to wipe the local state before it calls my unmounting function.
Consider t...
Biebel asked 14/12, 2020 at 13:54
9
I am using ant design on my project. I get data from redux store with useEffect like this;
const settingsRedux = useSelector(state => state.SETTINGS)
after that I use this data for defaultVal...
Alltime asked 16/4, 2020 at 6:53
6
Solved
I'm fetching data from a weather api using useEffect hook and declaring the dependency correctly as well. My state is still not being updated and I get errors in my render function because of that....
Ringnecked asked 30/7, 2019 at 2:22
8
Solved
How are you.
This is scenario of this issue.
Let's say there are 2 screens to make it simple.
enter A screen. useEffect of A screen called.
navigate to B screen from A screen
navigate back to A s...
Shaped asked 12/2, 2020 at 7:12
8
I am using react-native-testing-library to test my react-native component.
I have a component (for the purpose of this post, it has been over simplified):
export const ComponentUnderTest = () =>...
Schizogony asked 1/12, 2019 at 23:57
4
Solved
With regular React it's possible to have something like this:
class NoteEditor extends React.PureComponent {
constructor() {
super();
this.state = {
noteId: 123,
};
}
componentWillUnmoun...
Beanstalk asked 28/2, 2020 at 17:39
3
Solved
For example, if I have components A and B, and component B is the child of component A:
<A>
<B />
</A>
Inside A we have:
useEffect(() => {
console.log('Parent A useEffect...
Frei asked 12/10, 2019 at 8:40
6
Solved
I've been learning React and I read that the function returned from useEffect is meant to do cleanup and React performs the cleanup when the component unmounts.
So I experimented with it a bit but...
Muscadel asked 13/7, 2019 at 21:46
1 Next >
© 2022 - 2025 — McMap. All rights reserved.