父级调用子级函数,但无法启动组件引用

时间:2019-11-16 16:04:33

标签: reactjs react-native

我收到此警告:

Function components cannot be given refs. Attemps to access this ref will fail. Did you mean to use React.forwardRef()?

父母:

constructor(props) {
    super(props);
    this.tElement = React.createRef();
  }

compoenentDidMount() {
    this.tElement .current.loadTx();
}

调用子组件:

 <Tt ref={this.tElement } />

该子项是React.Cmponent导出为react-redux connect:

import { connect } from 'react-redux';

class Tt extends Component {
   loadTx = async () => {
   }
} 

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(TransactionHistoryScene);

我通过使用组件道具和状态来刷新组件来解决它。

0 个答案:

没有答案