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

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

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 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