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

157
Views
Why the value assign inside the useEffect is not global?

Can you help me to understand, why the value assign inside the useEffect is not global?

Please see code below:

import React, { useState, useEffect } from "react";
import "./App.css";

function App() {
  let value;

  useEffect( () => {
    value = 2
  }, []);

  console.log("Value: ", value)

  return (
    <>
    { value }
    </>
  );
}

export default App;

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Re-assigning value does not cause a re-render, additionally, every render cycle, value is reset to undefined. What you want is something like:

import React, { useState, useEffect } from "react";
import "./App.css";

function App() {
  const [value, setValue] = useState();

  useEffect( () => {
    setValue(2)
  }, []);

  console.log("Value: ", value)

  return (
    <>
    { value }
    </>
  );
}

export default App;
about 4 years ago · Juan Pablo Isaza 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!