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

159
Vistas
My variable is undefined in my render method

I have a variable that I need in my React class.

But when I define it in the construtor, it becomes undefined when I try to use it in the render() method.

How can I make it so that my variable is available in the render() method?

Here is what I have:

export default class GameConsole extends React.PureComponent {

constructor(props) {
    super(props);

    var domainUrl = window.location.origin;
}

render() {
    return (
        <div>
            <GameControl
               init={{
                  masterUrl = domainUrl;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Write this:

export default class GameConsole extends React.PureComponent {

constructor(props) {
    super(props);
        
}


render() {

var domainUrl = window.location.origin;
    return (
        <div>
            <GameControl
               init={{
                  masterUrl = domainUrl;
about 4 years ago · Juan Pablo Isaza Denunciar

0

Assign the value to the component's local state:

constructor() {
  super();
  this.state = {
    domainUrl: window.location.origin,
  };
}

render() {
  // Can access it on `this.state` inside render
  this.state.domainUrl;
}
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