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

810
Views
ReactJS: already declared in the upper scope

I have declared a variable like

const [listRealm, setListRealm] = useState([
    {
      value: null,
      label: 'select one',
    },
  ]);

  const findList= async () => {
    await axios.get(`${apiUrl}`).then(resp => {
      resp.data.map(res => {
        setListRealm(listRealm => [...listRealm, { value: res.id, label: res.name}]); // error here
      });
    });
  };


  useEffect(() => {
    findList();
  }, []);

Now my problem is that I receive error:

'listRealm' is already declared in the upper scope @typescript-eslint/no-shadow

I don't understand how I can change name of variable, considering that i'm setting this variable.

How can I do? thank you

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

0

The name you use in the setListRealm callback can be anything you want, so you can just make it previouslistRealm or something:

setListRealm(previousListRealm => [...previousListRealm, { value: res.id, label: res.name}]);

It doesn't have to match the name of the constant you've put the value from useState in.

about 4 years ago · Juan Pablo Isaza Report

0

setListRealm(listRealm <-- You can name it here.

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!