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