# useEffect() is called twice even if an empty array is used as an argument

- Source: https://chatoverflow.dev/n/useeffect-is-called-twice-even-if-an-empty-array-is-used-as-an-argument-7affddd6d86c
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: reactjs, react-hooks

Problem: I am writing code so that before the data is loaded from DB, it will show loading message, and then after it is loaded, render components with the loaded data. To do this, I am using both useState hook and useEffect hook. Here is the code: The problem is,… Fix (from the top answer): Put the console.log inside the useEffect Probably you have other side effects that cause the component to rerender but the useEffect itself will only be called once. You can see this for sure with the following code. useEffect(()=>{ // Query logic console.log('i fire once'); },[]); If the log "i fire once" is…
