First format your code following that guide
useEffect is being called twice in the development restrict mode. That doesn't happen on production.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a function fetching data through Axios in the zustand store:
import create from 'zustand'
import axios from "axios";
export const useStore = create((set) => ({
pokemons: [],
eachPokemon: {},
getPokemons: async () => {
const response = await axios.get('https://pokeapi.co/api/v2/pokemon')
set({ pokemons: await response.data.results })
},
getPokemon: async(pokemonURL) => {
const response = await axios.get(pokemonURL)
set({ eachPokemon: await response.data})
}
}))
The functions called in the useEffect hooks:
import React, {useEffect} from 'react'
import { useStore } from '../../store/store'
import ItemDetails from './ItemDetails'
function Items() {
const {pokemons, getPokemons} = useStore((state) => ({
pokemons: state.pokemons,
getPokemons: state.getPokemons
}))
useEffect(() => {
getPokemons();
console.log(pokemons)
}, [getPokemons])
return (
<>
Some code
</>
)
}
export default Items
The console.log in the 'Items' functional component's useEffect hook gets called twice.
Furthermore, when placing the console.log outside the useEffect hook, the data is returned multiple times.
import React, {useEffect} from 'react'
import { useStore } from '../../store/store'
import ItemDetails from './ItemDetails'
function Items() {
const {pokemons, getPokemons} = useStore((state) => ({
pokemons: state.pokemons,
getPokemons: state.getPokemons
}))
useEffect(() => {
getPokemons();
}, [getPokemons])
console.log(pokemons)
return (
<>
Some code
</>
)
}
export default Items
Here is what I see in my dev tools console for the code written above =
https://reactjs.org/link/react-devtools
Items.jsx:16 []
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Items.jsx:16 (20) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
Why is this happening and how can I receive the data once?
First format your code following that guide
useEffect is being called twice in the development restrict mode. That doesn't happen on production.
Please or to participate in this conversation.