• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

782
Vistas
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 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

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 3 years ago · Juan Pablo Isaza Denunciar

0

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

about 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda