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

156
Views
REACT ROUTER - Class component (only) - rendering page - JSON File

i'm working on react router project (im beginner) to improve my skillz.

my problem:

I have a JSON file (Dragon ball Z). When i click on characters (like goku) i want to show his biography. Actually when i click on goku every biography of each characters are showed.

I know how to do it with function component (useLocation ect..) but i'm totally stuck wicth class component because i can't use hooks in it, what is the good way to do it ?

here is the project : DBZ REACT ROUTES

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Using react-router-dom v6 we can use useParams to read the params key within function component. With class component you can write an HOC function to archive the same thing

a higher-order component is a function that takes a component and returns a new component

import { useParams } from 'react-router-dom'

function withParams(Component) {
  return props => <Component {...props} params={useParams()} />;
}

class Charbio extends React.Component {
  componentDidMount() {
    let { id } = this.props.params;
    // get the bio by id here
  }

  render() {
    return API.map((element) => {
      return <p>{element.bio}</p>;
    });
  }
}

export default withParams(Charbio);
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!