新进展:
68行有值, 77行取不到值.
为什么?
执行2次setTimeout(),内外输出结果图:
看22,25行输出结果.
一一一一一一一一一一一一一一一一一一一一一一一一
在setTimeout()后打印console.log(this.state.newNode); 是有值的,也就是说state更新了,但是里的 label: this.state.newNode, 第一次没有更新,总是下一次输出上一次的值,总是慢一拍。
重要补充:
onDragStart = info => {
setTimeout(() => {
this.setState({
newNode: info.node._reactInternalFiber.memoizedProps.title
})
console.log(this.state.newNode); //有值
},10)
console.log(this.state.newNode); //无值
}
setTimeout()内部有值,外部无值.这样有办法在在render(){return()}的 return()里能取到值吗?
constructor() {
super();
this.state = {
newNode: ''
}}
onDragStart = info => {
setTimeout(() => {
this.setState({ newNode:info.node._reactInternalFiber.memoizedProps.title})
}, 10)
鼠标事件: