我正在尝试这样 做。
我一定是遗漏了什么,但我不明白为什么 current
总是 null
在这个例子中。
class App extends React.PureComponent {
constructor(props) {
super(props);
this.test = React.createRef();
}
render() {
return <div className="App">current value : {this.test.current + ""}</div>;
}
}
你可以 在这里 查看我的测试用例
原文由 Sharcoux 发布,翻译遵循 CC BY-SA 4.0 许可协议
因为您忘记将 ref 分配给某个 dom 元素。你只是在创造它。
像这样写:
工作示例。