reactjs 将JavaScriptReact类组件导出到TypeScript文件中

92vpleto  于 2023-02-04  发布在  React
关注(0)|答案(1)|浏览(90)
    • bounty将在3天后过期**。回答此问题可获得+50声望奖励。Sora希望引起更多人关注此问题。

是否有方法将JavaScriptReact类组件导出到TypeScript文件中?
下面的代码:

    • 登录. js**
class Login extends Component {

constructor(props) {
    super(props);
    this.usernameText = React.createRef();
    this.passwordText = React.createRef();
    this.urlText = React.createRef();
    this.keyPress = this.keyPress.bind(this);
  }

  .
  .   
  .
 }
 export default  Login;
    • 索引. ts**
const Login = require("./uiManagement/jiraUI/Login/Login");
export {
 Login as JiraUiLogin 
}

在另一个项目中,我为上面的代码做了一个**npm import**来使用登录组件:

import { Component } from "react";
import { JiraUiLogin } from "infosysta-typescript-core";
class mLogin extends Component {
  render() {
    return (
      <JiraUiLogin />
    )
  }
};
export default mLogin

但我遇到了以下错误:

pw9qyyiw

pw9qyyiw1#

将Login.js文件更改为typescript怎么样?

import React, { Component } from "react";

interface Props {
}
interface State {

}

class Login extends Component<Props, State> {
  usernameText = React.createRef<HTMLInputElement>();
  passwordText = React.createRef<HTMLInputElement>();
  urlText = React.createRef<HTMLInputElement>();
  keyPress = (event: React.KeyboardEvent) => {
    
  };
}

export default Login;

标题

相关问题