super 在 React 中被删除 [英] super got strikethrough in React

查看:50
本文介绍了super 在 React 中被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

import React, { Component } from 'react';从 'prop-types' 导入 PropTypes;从 'axios' 导入 axios;从'react-redux'导入{连接};从'../../reducks/auth/actions'导入*作为动作;从@material-ui/core"导入 CircularProgress类 Add_Want_Item_Form 扩展组件 {构造函数(道具){超级(道具);this.state = {//#インプット情报用信息:{名称: '',所有者: '',关键字 1: '',关键字 2: '',关键字 3: '',平淡:'',网址:'',},//验证用//urlは必须项目ではないので验证には含めない信息: {名称: '',关键字 1: '',关键字 2: '',关键字 3: '',平淡:'',},};this.handleChange = this.handleChange.bind(this);}componentDidMount() {公理.get('http://localhost:8000/api/user/' + this.state.uid).then((res) => console.log(res)).catch((err) => console.log(err));}句柄变化(e){const name = e.target.name;常量值 = e.target.value;const {信息,消息} = this.state;this.setState({信息:{ ...信息,[名称]:值},});this.setState({消息:{ ...消息,[名称]:this.validator(名称,值)},});}////...////使成为() {const {信息,消息} = this.state;返回 (<div><label>商品名</label><输入名称=名称"类型=文本"value={this.state.info.name} onChange={this.handleChange}/><p>{this.state.message.name}</p>

);}}const mapStateToProps = (状态) =>{返回 {uid:state.uid,};};导出默认连接(mapStateToProps)(Add_Want_Item_Form);

问题

super 在 React 中得到删除线,尽管它没有出现在 stackoverflow 中.我正在使用 VS Code (1.49.0).

我在安装 @material-ui/core 后才注意到.老实说,我无法确切说出这件事发生的时间.

我想原因不是 @material-ui/core 但我不知道是什么原因造成的.除此之外,我不知道它对我的项目有什么影响.

什么意思?这个删除线会发生什么?请教我好吗?

非常感谢.

解决方案

好像和 VS Code 的新更新有关:https://code.visualstudio.com/更新/v1_49#_deprecated-tag-support-for-javascript-and-typescript

为了解决这个问题,现在,您可以将 super(props) 更改为 super() ,它会修复它.如果您没有在 constructor() 内的代码中使用 props ,它不会影响您的代码,这意味着它不会影响您的代码,因为您没有在构造函数内使用 props.

Code

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);

Problem

super gets strikethrough in React although that doesn't show up in stackoverflow. I am using VS Code (1.49.0).

I just noticed after I installed @material-ui/core. Honestly, I cannot say exactly when this happened.

I guess the cause is not @material-ui/core but I don't know what causes this. In addition to that, I don't know what effects it has to my project.

What does it mean? And what happens this strikethrough? Would you please teach me them?

Thank you very much.

解决方案

It seems it is related to the new update of VS Code: https://code.visualstudio.com/updates/v1_49#_deprecated-tag-support-for-javascript-and-typescript

To fix the issue, for now, you can change super(props) to super() and it will fix it. It will not affect your codes if you are not using props in the codes inside constructor(), which means it will not affect your code since you have not used props inside constructor.

这篇关于super 在 React 中被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆