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

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

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 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