Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda