Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!