我有时会遇到问题。
class AddUser extends React.Component<ModalProps, ModalState> {
state: ModalState = {
isShow: false
};
showModal = () => {
this.setState({ isShow: true });
};
searchUser = ( value : string) => {
this.props.updateUser(value);
}
render() {
return (
<Modal
title="Add User"
visible={this.state.isShow}
onCancel={() => this.setState({ isShow: false })}
onOk={() => this.setState({ isShow: false })}
>
<Input.Search allowClear onSearch={value => this.searchUser(value)}/>
</Modal>
);
}
}
const mapStateToProps = (state: IState) => ({
user : state.user
})
export default connect(mapStateToProps, {addUserGroupByUsername, updateUser}, null, {forwardRef : true})(AddUser);
这是连接到Redux存储的类组件。
我想在父组件中获得它:
private modalElement: React.RefObject<>;
constructor (props: GroupProps) {
super(props);
this.modalElement = createRef();
}
但是 Adduser 类型在这里变得有价值,而不是一种类型。 我该如何解决?
此处错误:
Type 'RefObject<any>' is not assignable to type '<T>() => RefObject<T>'.
Type 'RefObject<any>' provides no match for the signature '<T>(): RefObject<T>'. TS2322
58 | constructor (props: GroupProps) {
59 | super(props);
> 60 | this.modalElement = React.createRef<AddUser>();
| ^
61 | }
我不确定在这里应该使用哪种类型?