Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

196
Vistas
Cannot access 'sizeWidth' before initialization

I am trying to make a react app where I can style a Button using JavaScript by changing variables such as width, height, etc, but I am getting this error when trying to pass "width" and "height" values from my index.js to my App.js (where I export my Button)

I am receiving the error: "Cannot access 'sizeWidth' before initialization" when I reload my React app. (line 13)

App.js:

import {sizeWidth, sizeHeight} from './index';
import {Component} from "react";


// units are in px, colors are in HEX, rotation is in degrees

//element

class Page extends Component {
    render() {
        return (
            <Button width={sizeWidth} height={sizeHeight}/> // error is here
        )
    }
}

class Button extends Component {
    render() {
        return (
            <button className="element" style={{ width: sizeWidth, height: sizeHeight }}>BUTTON</button>
        );
    }
}

export default Page;

index.js:

import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

const sizeWidth = 238;
const sizeHeight = 76;

export {sizeWidth, sizeHeight}

Would be appreciated a lot if someone would be able to assist me in solving this issue! I am very new to React.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I found the answer to my question, I stupidly rendered my App using ReactDOM.render before initializing my variables...

facepalm

about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda