【发布时间】:2016-10-29 18:32:00
【问题描述】:
我在componentDidMount() 中创建了一个变量,我希望它在componentDidUpdate() 中可用。有什么想法吗?代码如下所示:
class Example extends Component {
componentDidMount() {
const myVariable = 'this thing';
}
componentDidUpdate() {
// I'd like my variable to be accessible here
console.log(myVariable);
}
render() {...}
}
【问题讨论】:
标签: javascript reactjs scope