Search code examples
javascriptreactjsjsxreact-bootstrap

React, Unterminated Header JSX Element


Hi I am trying to set up a basic example of react, this is my code to show the page. Could you recommend how I can compose this element better. What is wrong with my Header.js that I am importing into my app?

Header.js

import Jumbotron from "react-bootstrap/Jumbotron";
import ButtonGroup from "react-bootstrap/ButtonGroup";
import Button from "react-bootstrap/Button";

export default class Header extends React.Component {
  render() {
    return (
      <Jumbotron fluid>
        <h1 className="header">Welcome to Zach's page</h1>
        <ButtonGroup aria-label="Basic example">
          <Button variant="secondary">Left</Button>
          <Button variant="secondary">Middle</Button>
          <Button variant="secondary">Right</Button>
        </ButtonGroup>
      </Jumbotron>
    );
  }
}

App.js

import React from "react";

// Importing the Bootstrap CSS
import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";
import Header from "../src/Header";
import HeaderNavigation from "../src/HeaderNavigation";
import Form from "../src/Form";
import Body from "../src/Body";

const App = () => (
  <div>
    <div className="container">
      <HeaderNavigation />
      <div className="contents">{this.props.activeRouteHandler()}</div>
    </div>

    <Header />
    <Body>
      <Form />
    </Body>
  </div>
);

export default App;

Apptest.js

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import Header from "../src/Header";
import HeaderNavigation from "../src/HeaderNavigation";
import Form from "../src/Form";
import Body from "../src/Body";

it("renders without crashing", () => {
  const div = document.createElement("div");
  ReactDOM.render(<App />, <Header />, <HeaderNavigation /> <Form />, <Body />);
  ReactDOM.unmountComponentAtNode(div);
});

the Errors

'React' is not defined. (no-undef) eslint

/src/Jumpotron.js: Unterminated JSX contents (16:14) 14 | <Button variant="secondary">Middle</Button> 15 | <Button variant="secondary">Right</Button> > 16 | </ButtonGroup> | ^ 17 |

Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? 9 | it("renders without crashing", () => { 10 | const div = document.createElement("div"); > 11 | ReactDOM.render(<App />, <Header />, <HeaderNavigation /> <Form />, <Body />); | ^ 12 | ReactDOM.unmountComponentAtNode(div); 13 | }); 14 | (null)


Solution

  • You have an import named Jumbotron then trying to name a class Jumbotron. Either change your class name or alias your import.

    EDIT 1: You need import React, {Component} from 'react'; to your Jumbotron component. Key piece for building react components.