constructor(props) {
super(props);
this.myRef = React.createRef();
}
render() {
return <div ref={this.myRef} />;
}
我可以在渲染组件后创建这样的组件引用。我需要的是将这个组件 ref 保存在 redux 存储中。我可以将它保留为状态变量,但 redux 会抛出如下错误:
Invalid attempt to destructure non-iterable instance
有什么方法可以在应用程序中将组件 ref 保存为全局变量?
ref 对象的深拷贝,解析 JSON 字符串无效...
最佳答案
你可以在connect中使用withRef特性
export default connect(
mapStateToProps,
mapDispatchToProps, null, {withRef: true})(myComponent);
引用下面使用 withRef 的链接示例
sample code link
https://stackoverflow.com/questions/54943358/
相关文章:
angular7 - 无法加载 server.component.html
html - 如何判断 Chrome 表单不包含信用卡字段?
python-3.x - 在将多头 pandas 数据帧输出到 excel 时摆脱索引
amazon-web-services - 为通过 UserData 创建 AMI 准备 Windo
android-studio - adb.exe start-server failed——必要时手
ansible - 如何获得 ansible playbook 运行更改的任务总数?
json - 将包含 json 数据的 pandas 数据框的列拆分为多个列