'UserInput' is defined but never used no-unused-vars 'UserOutput' is defined but never used no-unused-vars

huangapple go评论91阅读模式
英文:

'UserInput' is defined but never used no-unused-vars 'UserOutput' is defined but never used no-unused-vars

问题

以下是您要翻译的内容:

App.js

import React, { Component } from 'react';
import './App.css';
import UserInput from './UserInput/UserInput';
import UserOutput from './UserOutput/UserOutput';

class App extends Component {

  render() {
    return (
      <div className="App">
        <p>some random text</p>
        <UserInput />
        <UserOutput /> 
      </div>
    );
  }
}

export default App;

UserInput.js

import React from 'react';

const userInput = () => {
  return <input type="text" />;
};

export default userInput;

UserOutput.js

import React from 'react';

const userOutput = () => {
  return (
    <div>
      <button>hello </button>
    </div>
  );
};

export default userOutput;

请注意,我已经将代码中的HTML标签进行了恢复,以便更好地阅读。如果您需要任何其他帮助,请随时提出。

英文:

newbie to react, following a series of lecture
*i just trying to excute this simple code but something went wrong and gave me error like 'UserInput' is defined but never used although path and src sets perfectly ok ***

App.js

import React, { Component } from &#39;react&#39;;
import &#39;./App.css&#39;;
import  UserInput from &#39;./UserInput/UserInput&#39;;
import UserOutput from &#39;./UserOutput/UserOutput&#39;;

class App extends Component() {

  render() {
  return (
    &lt;div className=&quot;App&quot;&gt;
      &lt;p&gt;some random text&lt;/p&gt;
      &lt;userInput /&gt;
      &lt;userOutput /&gt; 
    &lt;/div&gt;
    
  );
}
}
export default App;

UserInput.js


import React from &#39;react&#39;;
const userInput = () =&gt; {

return &lt;input type=&quot;text&quot; /&gt;;
};
export default userInput;

UserOutput.js


import React from &#39;react&#39;;

const userOutput = () =&gt; {

return(&lt;div&gt;
    &lt;button&gt;hello &lt;/button&gt; 
    &lt;/div&gt;)


};
export default userOutput;

答案1

得分: 0

改进

class App extends Component{}定义为class App extends Component() {}

将导入的UserInputUserOutput定义如下:

<UserInput />
<UserOutput />

App.js

import UserInput from './UserInput/UserInput';
import UserOutput from './UserOutput/UserOutput';

class App extends Component {
  render() {
    return (
      <div className="App">
        <p>一些随机文本</p>
        <UserInput />
        <UserOutput />
      </div>
    );
  }
}

export default App;

您的代码的在线演示 demo

英文:

Improvement

Define class App extends Component{} not class App extends Component(){}

Define imported UserInput,UserInput like

      &lt;UserInput /&gt;
      &lt;UserOutput /&gt; 

App.js

import  UserInput from &#39;./UserInput/UserInput&#39;;
import UserOutput from &#39;./UserOutput/UserOutput&#39;;

class App extends Component{

  render() {
  return (
    &lt;div className=&quot;App&quot;&gt;
      &lt;p&gt;some random text&lt;/p&gt;
      &lt;UserInput /&gt;
      &lt;UserOutput /&gt; 
    &lt;/div&gt;
  );
}}
export default App;

Live demo for your code demo

huangapple
  • 本文由 发表于 2020年1月3日 19:20:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577700.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定