[英]how to declare a react ref in props function when using typescript
I need to pass the refs from one component to a function passed in from another component as a prop, and I need to do it in typescript. 我需要将引用从一个组件传递到从另一个组件传递的函数作为道具,而我需要在打字稿中进行。
So the relevant code inside the child component is 所以子组件内部的相关代码是
class Login extends Component<IProps, IState> {
private emailRef = React.createRef<HTMLInputElement>();
private passRef = React.createRef<HTMLInputElement>();
constructor(props?) {
super(props);
}
login = () => {
const email = this.emailRef.current;
const pass = this.passRef.current;
this.props.login(email, pass);
}
which is ok, but now inside of my IProps I should declare login. 没关系,但是现在我应该在IProps内部声明登录名。
And I can't figure out how to do it? 而且我不知道该怎么做?
As an example 举个例子
interface IProps {
login: (u: any, p: any) => any,
errorMessage: ''
}
obviously those anys are no good, and need to be replaced with something better. 显然,这些都不好,需要用更好的东西代替。 How do I specify that I am in fact going to be passing a react ref here?
我如何指定我实际上将在此处传递react ref?
Declare in constructor()
as, 在
constructor()
声明为,
constructor(props?) {
super(props);
this.emailRef = React.createRef();
this.passRef = React.createRef();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.