Im new to reactjs and trying to populate a form from a value retrieved from firebase.
Here is where the value is fetched.
componentWillMount: function () {
var projectId = this.props.params.key;
this.fb = new Firebase(rootUrl + 'items/');
var projectRef = this.fb.child(projectId);
var subjectproject = "NA";
projectRef.child("subject").on("value", function(snapshot) {
subjectproject = snapshot.val();
});
},
And here is the form input that i want to populate
<div className="col-lg-6">
<div class="input-group">
<label class="control-label required" for="project_project_title">Subject</label>
<input defaultValue={subjectproject} value={this.state.subject} placeholder="Subject" onChange={this.handleInputChangeSubject} type="text" className="form-control"/>
</div>
</div>
All i ever get is projectSubject is undefined. How do i create a variable that can be used to provide a defaultvalue.
Edit -
projectRef.child("subject").on("value", function(snapshot) {
textsubject = (snapshot.val());
this.setState({subject: textsubject});
});
Throws FIREBASE WARNING: Exception was thrown by user callback. TypeError: this.setState is not a function