Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Form' is not defined react/jsx-no-undef

Hi with the app react below I have to manage a form to verify the login to a page, the parameters are email and password but when I execute the code the following error is printed,error: Line 33: 'Form' is not defined react/jsx-no-undef

Javascript code:

import React, { Component } from 'react';
import { Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap";
import logo from './logo.svg';

import './Home.css';

class Home extends Component {
  constructor(props) {
    super(props);

    this.state = {
      email: "",
      password: ""
    };
  }

  validateForm() {
    return this.state.email.length > 0 && this.state.password.length > 0;
  }
  handleChange = event => {
    this.setState({
      [event.target.id]: event.target.value
    });
  }

  handleSubmit = event => {
    event.preventDefault();
  }

  render() {
    return (
      <div className="Login">
        <Form onSubmit={this.handleSubmit}>
          <Form.Group controlId="email" bsSize="large">
            <Form.Control
              autoFocus
              type="email"
              value={this.state.email}
              onChange={this.handleChange}
            />
          </Form.Group>
          <Form.Group controlId="password" bsSize="large">
            <Form.Control
              value={this.state.password}
              onChange={this.handleChange}
              type="password"
            />
          </Form.Group>
          <Button
            block
            bsSize="large"
            disabled={!this.validateForm()}
            type="submit"
          >
            Login
              </Button>
        </Form>
      </div>
    );
  }
}

export default Home;
like image 502
riki Avatar asked May 19 '19 08:05

riki


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' .

How do you fix ReactDOM is not defined?

To fix that, you will need to make sure the module exists in your project, and you call it correctly. Here is the example: import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; ReactDOM. render(<App />, document.

How do you make a functional component react?

We can create a functional component to React by writing a JavaScript function. These functions may or may not receive data as parameters. In the functional Components, the return value is the JSX code to render to the DOM tree. Example: Program to demonstrate the creation of functional components.


1 Answers

Seems like you forgot to import Form, just add it:

import { Form, Button, FormGroup, FormControl, ControlLabel } from "react-bootstrap";
like image 60
Sagiv b.g Avatar answered Nov 02 '22 23:11

Sagiv b.g