javascript - 'Component' is not defined reactjsx-no-undef - Stack Overflow

I created one ponent and I'm exporting itimport React , {Component} from 'react'import

I created one ponent and I'm exporting it

import React , {Component} from 'react'
import logo from './logo.svg';

class Item extends Component {
     
  render () {
    return (
    
       <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">ReactND - Coding Practice</h1>
        </header>
        <h2>Shopping List</h2>
        <form onSubmit={this.addItem}>
          <input
            type="text"
            placeholder="Enter New Item"
            value={this.state.value}
            onChange={this.handleChange}
          />
          <button disabled={this.inputIsEmpty()}>Add</button>
        </form>

        <button onClick={this.deleteLastItem} disabled={this.noItemsFound()}>
          Delete Last Item
        </button>
        </div>
    )  
  }
}

export default Item

And I want to use this ponent in my app ponent as below

import React from 'react';
import './Item';

class App extends React.Component {
 
  render() {
    return (
        <div>      
        <Item />
      </div>
    );
  }
}

export default App;

But I got this error in App.js

 Line 9:  'Item' is not defined  react/jsx-no-undef

pretty sure I did everything. I have exported and imported this ponent , so what I'm missing here?

I created one ponent and I'm exporting it

import React , {Component} from 'react'
import logo from './logo.svg';

class Item extends Component {
     
  render () {
    return (
    
       <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">ReactND - Coding Practice</h1>
        </header>
        <h2>Shopping List</h2>
        <form onSubmit={this.addItem}>
          <input
            type="text"
            placeholder="Enter New Item"
            value={this.state.value}
            onChange={this.handleChange}
          />
          <button disabled={this.inputIsEmpty()}>Add</button>
        </form>

        <button onClick={this.deleteLastItem} disabled={this.noItemsFound()}>
          Delete Last Item
        </button>
        </div>
    )  
  }
}

export default Item

And I want to use this ponent in my app ponent as below

import React from 'react';
import './Item';

class App extends React.Component {
 
  render() {
    return (
        <div>      
        <Item />
      </div>
    );
  }
}

export default App;

But I got this error in App.js

 Line 9:  'Item' is not defined  react/jsx-no-undef

pretty sure I did everything. I have exported and imported this ponent , so what I'm missing here?

Share Improve this question asked Dec 17, 2020 at 18:00 RahulRahul 911 gold badge2 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You have to name your import.

import React from 'react';
import Item from './Item';

class App extends React.Component {
 
  render() {
    return (
        <div>      
        <Item />
      </div>
    );
  }
}

export default App;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742297909a4417491.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信