Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Button' is not defined react/jsx-no-undef react.js

im a noob in React.js , and just messing around with components and event listeners , i am trying to Add eventlistener to button but it doesnt work for some reason... I tried to import elemental but that just gives a bunch of other errors , can somone please tell me how i can get this to work ? thanks

import React from 'react'; 
import ReactDOM from 'react-dom';



class Passiing extends React.Component {
  scream() {
    alert('you passed!');
  }

  render() {
    return <Button onClick={this.scream}>Did you pass?</Button>;
  }
}

ReactDOM.render(<Button />, document.getElementById('app'));



export default Passiing; 
like image 752
Leon Bogod Avatar asked May 22 '18 13:05

Leon Bogod


People also ask

How do I fix JSX without undef?

The React. js error "X is not defined react/jsx-no-undef" occurs when we forget to import a function, class or a variable in our code before using it. To solve the error, make sure to import the value before using it in your code, e.g. import {myFunc} from 'my-package' .


2 Answers

You will need to import Button using react-bootstrap.

import { Button} from 'react-bootstrap';

In order for the style to appear, please install bootstrap and import 'bootstrap/dist/css/bootstrap.css' and add it in index.js

To use button,

Submitenter image description here

like image 160
John Samuel Avatar answered Nov 06 '22 09:11

John Samuel


You could use the HTML5 <button> tag for your button. If you use a capital letter for a tag in React it assumes that is a component rather than a "regular" tag.

like image 32
David Boland Avatar answered Nov 06 '22 07:11

David Boland