Quick one, I’m getting currentUser is undefined from this code:
// Bio component
Bio = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
return {
currentBio: Meteor.user()
}
},
getInitialState: function() {
return ({value: this.data.currentUser.profile.bio });
},
handleChange: function(event) {
this.setState({value: event.target.value});
},
bioSubmit(event) {
event.preventDefault();
// Parse the input
var bioInput = document.getElementById( "bio-field" ).value;
var bioParse = parseMarkdown( bioInput );
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
'profile.bio': bioParse
}
});
},
render: function() {
var value = this.state.value;
return (
<form onSubmit={this.bioSubmit}>
<div className="form-group">
<h3>Bio</h3>
<textarea className="form-control sharp" id="bio-field" value={value} onChange={this.handleChange}></textarea>
</div>
<button type="submit" className="btn btn-primary sharp">Submit</button>
</form>
)
}
});
(I’m not messing around with the code snippet above, Discourse seems to be buggy with code input atm)
I’m assuming it’s because React is using getInitialState
before getMeteorData
so the currentUser will be undefined? If so, then does anyone have a workaround? And if not, does anyone know why I’m getting undefined!? This profile stuff is getting a bit annoying now, the rest of my app is pretty much done and I’ve run into loads of roadblocks on the last bit (typical really…)
Cheers.