我有一个 React 组件,我想在单击时切换一个 css 类。
所以我有这个:
export class myComponent extends React.Component {
  constructor() {
    super();
    this.state = { clicked: false };
    this.handleClick = this.handleClick.bind(this);
  }
  render() {
    return (
      <div>
        <div onClick={this.clicked}><span ref="btn" className="glyphicon"> </span></div>
      </div>
    );
  }
  handleClick() {
    this.refs.btn.classList.toggle('active');
  }
  componentDidMount() {
    this.refs.btn.addEventListener('click', this.handleClick);
    this.setState({
      clicked: this.state.clicked = true,
    });
  }
  componentWillUnmount() {
    this.refs.btn.removeEventListener('click', this.handleClick);
    this.setState({
      clicked: this.state.clicked = false,
    });
  }
}
这个问题是 ESLint 一直告诉我“this.refs”已贬值。
我该怎么办?我该如何修复它以使其不使用折旧的代码?