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

80
Visualizações
forEach not working in ReactJs while using data from array

I am encountered a problem while learning reactJS.Here, I have a HomePage Component where forEach not working in ReactJs while I am trying to get the data from the array defined. Below is the code:

import React, { useEffect } from "react";
import ChessRankings from "../components/ChessRankings";
import "../App.css";


import gifPath from "../assets/pieceChess.gif";

const paraContent = [

"ChessMania is a website that gives the latest update for chess. Chess is one of the 
most tactical games played across the globe. Here our main focus is to present the 
various chess articles. However, this website also covers the basics of learning 
objectives of chess as well as current chess rankings at the international level.",

"Subsequently, we also cover the common FAQs related to chess, the notation, and the 
type of game played in chess. You also get a glimpse of various prestigious 
tournaments of chess played across the globe within a chess calendar and about the 
esteemed players taking part in, it.",

"The last section takes you through the profile of any Lichess Player that loves 
chess. The profile section displays the basic introduction, including name, 
nationality, followers, and total games played. Later it shows the player's rating in 
each variant and the percentage of wins and losses. It also shows the chess variant 
played by that user most and which are least. Finally, it shows the statistics of the 
player in the puzzle section.",

];

const HomePage = () => {
  useEffect(() => {
     document.title = "ChessMania - Home";
  }, []);

return (
<>
  <h1>Hello , Welcome to Chess Mania</h1>
  <br />
  <div className="text-center">
    <img src={gifPath} alt="gif" />
  </div>
  <hr />

  {
    paraContent.forEach((element) => {
    //console.log(element);
    return (<p className="about-paragraph">{element}</p>)
     })
  }

  
    </>
  );
};

 export default HomePage;

I am unable to figure out the error? Anyone, please tell me what is the problem here?

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

0

Use map function inside render element:

https://codesandbox.io/s/react-code-slr6e

paraContent.map((element, index) => {
    //console.log(element);
    return (<p className="about-paragraph" key={index}>{element}</p>)
})
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