下面是几个适合使用 refs 的情况
1、处理焦点、文本选择或媒体控制
2、触发强制动画
3、集成第三方 DOM 库
<div ref={() => this.domName = React. createRef()}></div>
// 修改dom样式
this.domName.style.background = "pink";
// styledComponents样式化的元素 const KillItem = styled.div` font-size: 16px; cursor: pointer; font-weight: 600; `; <KillItem innerRef={() => this.domName = React.createRef()} /> // 修改dom样式 this.domName.style.background = ‘pink‘;
// 组件dom <Row type="flex" align="middle" innerRef={()=>this.domName = React.createRef()}></Row> // 修改dom样式 this.domName.style.background = "pink";
原文:https://www.cnblogs.com/dadouF4/p/11646789.html