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

449
Vistas
How to export state variable of react.js?

How to export state variable of react.js? means we have a state variable in react.js and this state variable needs to be in another component then how to we export that component.

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

0

Just declare your state, import the Component which you want to send the state variable and then pass it as attribute/parameter. Something is this:

import Data from './data';
import React, { Component } from "react";
import { connect } from "react-redux";
class Test extends Component {
    this.state = {
                firstName: "",
                lastName: "",
                dateOfBirth: "",
                emailAddress: "",
                fatherFirstName: "",
                fatherLastName: ""
            }

    componentDidMount() {
            this.props.setValues();
        }

    setValues= async () => {
            this.setState({
                firstName: "Teddy",
                lastName: "Bear",
                dateOfBirth: 2000-12-07,
                emailAddress: "teddybear@gmail.com",
                fatherFirstName: "Jonhathan",
                fatherLastName: "Bear"
            })
        }
render(){
return(
     <Container>
         <Data
             data={this.state}
         />
     </Container>
    )
   }

}
export default Test;

This is how it is done; how state variables are sent from one component to another component. You just need to send it as a parameter in a function. And this data sent in Data is used as this.props.

https://reactjs.org/ this site all you can start with and you can refer to this whenevr possible. I hope this simple interpretation will atleast tell you how it is done

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