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

81
Visualizações
How to replace page with a component

Let's say we have a blog page with a div class of content and there are previews of articles.

What I want to do is to replace div class of content with the specific article. How can I achieve this?


function Blog() {
    redirectToArticle(id) = () => {
       title = getTitle(id)
       content = getContent(id)
       {/*## code to replace div 'content' with <Article title={title} content={content}/>*/}
   } 

   return(
   <div className="content">
    <div onClick={redirectToArticle(1)}>
        <h1>Article Title 1</h1>
        <p>Short preview from the article here...</p>
    </div>
   </div>
   )
}

Article example:

class Article extends React.Component {
    constructor(props) {
      super(props);
      this.state = { title: 'Title', content: 'Lorem ipsum dolor sit amet.. . .. . . . . . . . . .'};
    }
    
  render(){
    return(
    <>
    <h1>{this.title}</h1>
    <p>{this.content}</p>
    </>
    )
  }
  
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Why would you like to replace that div? Isn't it better to display the thumbnail with the basic information + onClick route to the main article? I highly recommend using NextJS for that one - static props will help you a lot with that and will ensure you have a good structure - but with a simple CRA you can do it as well. Display a thumbnail with a short description and add onClick a page of the article with all the details and passed props.

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