Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

445
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!