Home > Blockchain >  React div problems
React div problems

Time:04-01

Im doing a React Web, and I have an error from div of validateDOMNesting
I dont know how resolve this error or fix.

Warning: validateDOMNesting(...): <body> cannot appear as a child of div<br/>.
    at body<br/>
    at Home<br/>
    at Routes<br/>
    at div<br/>
    at App<br/>

I have the view Home.js that have a nav and an image, but the error is in the body, maybe a render in all body?.

import React from 'react'
import "bootstrap/dist/css/bootstrap.min.css";
import "./listar.css"

function Home() {
    return (
        <body className='hola'>
            <div className="container">
                <nav className="navbar navbar-expand-lg navbar-light bg-light">
                    <div className="container-fluid">
                        <a className="navbar-brand" href="#">LOGO</a>
                        <button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                            <span className="navbar-toggler-icon"></span>
                        </button>
                        <div className="collapse navbar-collapse justify-content-end" id="navbarNav">
                            <ul className="nav justify-content-end ">
                                <li className="nav-item ">
                                    <a className="nav-link " href="#">Inicio</a>
                                </li>
                                <li className="nav-item">
                                    <a className="nav-link " href="#">Peliculas</a>
                                </li>
                                <li className="nav-item">
                                    <a className="nav-link " href="#">Series</a>
                                </li>
                                <li className="nav-item">
                                    <a className="nav-link " href="#">Noticias y Actores</a>
                                </li>
                                <li className="nav-item">
                                    <a className="nav-link " href="#">Sobre nosotros</a>
                                </li>
                                <li className="nav-item">
                                    <a className="nav-link " href="#">Inicio de Sesion</a>
                                </li>
                            </ul>
                            <form className="d-flex ">
                                <input className="form-control me-2" type="search" placeholder="Search" aria-label="Search" />
                                <button className="btn btn-outline-success" type="submit">Search</button>
                            </form>
                        </div>
                    </div>
                </nav>
                <div className="container row align-items-center imagen justify-content-center">
                    <img src="https://concepto.de/wp-content/uploads/2016/04/leer.jpg" alt="" className='w-auto' />
                </div>
            </div>
        </body>
    )
}
export default Home;

And this is my App.js, where I have the import of react-router-dom where I have the routes of my Web.


import './App.css';
import Listar from "./components/Listar"
import Sidebar from "./components/Sidebar"
import { Route, BrowserRouter as Router, Routes } from "react-router-dom"

import Register from './components/Register';
import Home from './components/Home';
import Login from './components/Login';

/* import Sidebar from "./components/Sidebar"; */

function App() {
  return (
    <div>
      <Router>
        <Routes>
          <Route path="/" element={<Home />} component={Home}>Sidebar</Route>
          <Route path="/listar" element={<Listar />} component={Listar}>Listar</Route>
          <Route path="/sidebar" element={<Sidebar />} component={Sidebar}>Sidebar</Route>
          <Route path="/login" element={<Login />} component={Login}>Login</Route>
          <Route path="/register" element={<Register />} component={Register}>Sidebar</Route>
        </Routes>
      </Router>

    </div>
  );
}

export default App;

CodePudding user response:

Somewhere above your Home component is already a body. Look in index.html or App.js

CodePudding user response:

Okay, the problem was that react has a body and if I add another body manually it gives an error so the solution is to remove the <body>.

  • Related