I have a component YourInformation:
class YourInformation extends React.Component{
constructor(props) {
super(props);
this.state = {
errors: {},
username:"",
alterEGO:"",
aboutYou:"",
stage:1,
blocking: false,
canSubmit: false
};
/**** binding to make context of this to class ***/
this.formValueChange = this.formValueChange.bind(this);
this.disableButton = this.disableButton.bind(this);
this.enableButton = this.enableButton.bind(this);
this.submitInformation = this.submitInformation.bind(this);
}
/**** function to handle change in form inputs ****/
formValueChange(event) {
event.preventDefault();
if (event.target.id == 'username') {
this.state.username = event.target.value;
} else if (event.target.id == 'alterEGO') {
this.state.alterEGO = event.target.value;
} else if (event.target.id == 'aboutYou') {
this.state.aboutYou = event.target.value;
}
return true;
}
/**** function to handle submit event ****/
submitInformation() {
let _that = this;
_that.setState({ blocking: true});
/***** fetch API for your information starts **********/
fetch(Constants.SERVER_URL + '/api/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: this.state.username,
alterEGO: this.state.alterEGO,
aboutYou: this.state.aboutYou,
stage: this.state.stage,
}),
}).then(function (response) {
And one more component i.e.,
class ProfileInformation extends React.Component{
constructor(props) {
super(props);
this.state = {
errors: {},
customUrl:"",
facebookLink:"",
youtubeLink:"",
instagramLink:"",
twitterLInk:"",
coverPic:"",
profilePic:"",
stage:3,
categories:[],
blocking: false,
canSubmit: false
};
/**** binding to make context of this to class ***/
this.formValueChange = this.formValueChange.bind(this);
this.disableButton = this.disableButton.bind(this);
this.enableButton = this.enableButton.bind(this);
this.submitProfile = this.submitProfile.bind(this);
this.getCategories = this.getCategories.bind(this);
}
I would like to access "username, alterEGO, aboutYOU" from yourInformation to ProfileInformation as I need these values prefilled in the profileInformation component form.
How can I fix this issue without using props, as I can not call ProfileInformation component into YourInformation component's render method?
yourInformationandProfileInformationand sends it to them as props.