Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Nothing is Displaying on my browser after running npm start in react app

after installing react-router-dom version 6 I tried to run npm start but I get a blank page with no error in my console. Below the first code is the code for the screen I want to display. Please can someone help me and show me what I am not doing correctly here.

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

import reportWebVitals from './reportWebVitals';
import MovieList from './component/movieList';

import  { BrowserRouter as Router, Routes, Route } from 'react-router-dom';


ReactDOM.render(
  <React.StrictMode>
    <Router>
    <Routes>
      <Route exact path = "/welcome" element = {MovieList}/>
    </Routes>
    </Router>
    
  </React.StrictMode>,
  document.getElementById('root')
);

reportWebVitals();
import { useState } from "react";

function MovieList() {
  const [searchTerm, setSearchTerm] = useState("")
  const [movies, setMovie] = useState([])
  const handleMovieSearchChange = (e) => {
    setSearchTerm(e.target.value);
  };

  const fetchMovie = (movieName) => {
    const searchUrl = `https://www.omdbapi.com/?s=${movieName}&page=2&apikey=2c2c85ae`;

    fetch(searchUrl)
      .then((response) => response.json())
      .then((result) => {
        setMovie(result.Search);
      });
  };

  const movieItems = movies.map((movie, index) => {
    return (
      <div key={index}>
       <img src={movie.Poster} alt="" />
        <h3>{movie.Title}</h3>
      </div>
    )
  })

  return (
    <div>
      <h1>Movie List Page</h1>Search
      <input type={"text"} onChange={handleMovieSearchChange} />
      <button onClick={() => fetchMovie(searchTerm)}>Search</button>
      {movieItems}
    </div>
  );
}

export default MovieList;

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You are getting a blank white screen because you are not rendering any component/page for the home route /. When the react application render initially renders the page which has path="/". there are two ways to fix it you can either render your welcome page at path / or you can redirect the user to the welcome screen if the user hits the home or / path.

First Method

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

import reportWebVitals from './reportWebVitals';
import MovieList from './component/movieList';

import  { BrowserRouter as Router, Routes, Route } from 'react-router-dom';


ReactDOM.render(
  <React.StrictMode>
    <Router>
    <Routes>
      <Route exact path = "/" element = {MovieList}/>
    </Routes>
    </Router>
    
  </React.StrictMode>,
  document.getElementById('root')
);

reportWebVitals();

Second Method

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

import reportWebVitals from './reportWebVitals';
import MovieList from './component/movieList';

import  { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';


ReactDOM.render(
  <React.StrictMode>
    <Router>
    <Routes>
      <Route exact path = "/welcome" element = {MovieList}/>
      <Route path="/" element={<Navigate replace to="/welcome" />} />
    </Routes>
    </Router>
    
  </React.StrictMode>,
  document.getElementById('root')
);

reportWebVitals();
about 4 years ago · Juan Pablo Isaza Relatório

0

I guess it is a componet: <Route exact path = "/welcome" element = {MovieList}/>

instead <Route exact path = "/welcome" element = {<MovieList/>}/>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda