gpt4 book ai didi

javascript - 类型 'findDOMNode' 上不存在属性 'typeof React'

转载 作者:行者123 更新时间:2023-11-30 11:45:02 24 4
gpt4 key购买 nike

我正在尝试研究如何使用 typescript 和 react js。我关注这个link我成功地安装了文件。这是 package.json

{
"name": "proj",
"version": "1.0.0",
"description": "hello world",
"main": "index.js",
"scripts": {
"test": "sample"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/react": "^0.14.55",
"@types/react-dom": "^0.14.19",
"react": "^15.4.1",
"react-dom": "^15.4.1"
},
"devDependencies": {
"awesome-typescript-loader": "^3.0.0-beta.17",
"source-map-loader": "^0.1.5",
"typescript": "^2.1.4",
"webpack": "^1.14.0",
"todomvc-app-css": "^2.0.0",
"todomvc-common": "^1.0.0"
}
}

这是我的 tsx 的代码。

import * as React from "react";
import * as ReactDOM from "react-dom";

export interface ItemProps { todoItem:string; getIndex:number; onDelete:any; onEdit:any; onChange:number}
interface ItemState {clickEdit:string;text:string}


export class TodoItem extends React.Component<ItemProps, ItemState> {

public state:ItemState;


constructor(props:ItemProps){
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.state = {clickEdit:"",text:this.props.todoItem};
}
public handleChange(e) {
this.setState({text: e.target.value});
}
public handleSubmit(e){

this.setState({clickEdit:""});
}
public delete(){
this.props.onDelete(this.props.getIndex);
}
public edit(){

var node = React.findDOMNode<HTMLInputElement>(this.refs["editField"]);
node.focus();
this.setState({clickEdit:"editing"});
this.props.onEdit(this.props.getIndex);
}
public render() {

return (
<li className={this.state.clickEdit}>
<div className="view">
<label onDoubleClick={e => this.edit()}>{this.props.todoItem}</label>
<button className="destroy" onClick={e => this.delete()}></button>
</div>
<input ref="editField" className="edit" onBlur={e => this.handleSubmit(e)} value={this.state.text} onChange={e => this.handleChange(e)} autoFocus={true} />
</li>
);
}
}

我不知道为什么我不能使用findDOMNode。我已经导入了 REACT。我是否遗漏了文件中的某些内容或需要安装的内容

最佳答案

尝试 从“react-dom”导入 ReactDOM; ReactDOM.findDOMNode().

关于javascript - 类型 'findDOMNode' 上不存在属性 'typeof React',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41274827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com