Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
Why My React Component Render Multiple Times In Console?

Im new in react. I'm Created two file App.js and UseEffect.js I'm Learn about lifecycle in react with function. So When I See in console, that's render multiple time. You can see my picture below.

My Console In Browser

This Is My Code

UseEffect.js

import React, {useState, useEffect} from "react";

function MyFunction(){
console.log('-> Function Init')

const [count, setCount] = useState(0)
const handleCount = () => {
    setCount(prevState => {
        return prevState+1
    })
}

//LifeCycle
useEffect(() => {
    console.log('my first effect')
})

console.log(`-> Start Render (${count})`)
return(
    <div>
            <h1>Function Component</h1>
            <p>
                <button onClick={handleCount}>Count</button>
                {count}
            </p>
    </div>
)}

export default MyFunction

App.Js

import './App.css';
import UseEffect from './components/UseEffect'

function App() {
   return (
      <div className="App">
      <UseEffect />
      </div>
   );
}

export default App;

How do it's work?, I Want it. it's just render one times.

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Your useEffect call is missing a dependency array. When you want it to run only at the initial render, you need to pass it an empty array as its dependencies.

useEffect(() => {
    console.log('my first effect')
}, [])

For further details, see this question.

about 4 years ago · Santiago Gelvez Report

0

Why it renders twice:

It's an intentional feature of the StrictMode. This only happens in development, and helps find accidental side effects put into the render phase. We only do this for components with Hooks because those are more likely to accidentally have side effects in the wrong place.

-gaearon

TLDR: It's a feature not a bug.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!