我有一个<Child />组件列表,然后我使用一个数组this.state.infos来生成这些子组件。如何使用this.refs来获取特定的子组件?
注意:this.state.infos = ['tom', 'mike', 'julie'];例如。
export default class Parent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      infos: {},
    };
  }
  // ignore logic for this.state.infos
  // ...
  render() {
    return (
        <div>
          {[...this.state.infos].map((info) => {
            return <Child
              ref={info}
            />
          })}
        </div>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)