gpt4 book ai didi

reactjs - super 在 React 中被删除

转载 作者:行者123 更新时间:2023-12-03 16:32:40 29 4
gpt4 key购买 nike

代码

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
import { connect } from 'react-redux';
import * as actions from '../../reducks/auth/actions';
import CircularProgress from "@material-ui/core"

class Add_Want_Item_Form extends Component {
constructor(props) {
super(props);
this.state = {
// #インプット情報用
info: {
name: '',
owner: '',
keyword1: '',
keyword2: '',
keyword3: '',
bland: '',
url: '',
},
// Validation用
//  urlは必須項目ではないのでValidationには含めない
message: {
name: '',
keyword1: '',
keyword2: '',
keyword3: '',
bland: '',
},
};
this.handleChange = this.handleChange.bind(this);
}

componentDidMount() {
axios
.get('http://localhost:8000/api/user/' + this.state.uid)
.then((res) => console.log(res))
.catch((err) => console.log(err));
}

handleChange(e) {
const name = e.target.name;
const value = e.target.value;
const { info, message } = this.state;
this.setState({
info: { ...info, [name]: value },
});
this.setState({
message: { ...message, [name]: this.validator(name, value) },
});
}

////

...

////

render() {
const { info, message } = this.state;
return (
<div>
<label>商品名</label>
<input name="name" type="text" value={this.state.info.name} onChange={this.handleChange} />
<p>{this.state.message.name}</p>
</div>
);
}
}

const mapStateToProps = (state) => {
return {
uid: state.uid,
};
};

export default connect(mapStateToProps)(Add_Want_Item_Form);

问题 super尽管在 stackoverflow 中没有出现,但在 React 中会被删除。
我正在使用 VS Code (1.49.0) .
我安装后才注意到 @material-ui/core .
老实说,我无法确切说出这件事发生的时间。
我猜原因不是 @material-ui/core但我不知道是什么原因造成的。
除此之外,我不知道它对我的项目有什么影响。
这是什么意思?这个删除线会发生什么?
你能教我吗?
非常感谢。

最佳答案

似乎与VS Code的新更新有关:
https://code.visualstudio.com/updates/v1_49#_deprecated-tag-support-for-javascript-and-typescript
要解决此问题,现在您可以更改 super(props)super()它会修复它。如果您不使用 props,它不会影响您的代码在里面的代码 constructor() ,这意味着它不会影响您的代码,因为您没有在构造函数中使用 props。

关于reactjs - super 在 React 中被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63861939/

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