Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

815
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda