我的React代码中看似不合理的行为。我在内部设置了两个元素,将一行代码放在另一行之后。我有console.log的每一个。两者都在分配之前正确打印,但只有比特币钱包变量(钱包)在状态而不是imageLink中正确表示。
module.exports = React.createClass({
getInitialState: function() {
return {
walletAddress: null,
image: null,
};
},
componentWillMount: function() {
Parse.User.currentAsync()
.then((user) => {
var wallet = user.get('address');
var imageLink = `https://api.qrserver.com/v1/create-qr-code/?size=500x500&data=bitcoin:${wallet}`;
console.log("wallet", wallet);
console.log("image: ", imageLink);
this.setState({image: imageLink});
this.setState({walletAddress: wallet});
console.log("imagezzz: ", this.state.imageLink);
})
},
答案 0 :(得分:0)
非常基本的错误,我分配给this.state.image并尝试记录this.state.imageLink。
我的语法错误,其他一切正常。感谢@James Allardice的澄清评论。