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

135
Views
Reaccionar: Incluya un nuevo accesorio para el componente secundario en el componente de orden superior

Esta es la clase de componente de orden superior

token es el prop que quiero incluir

 import React from "react"; export function requireAuthentication(Component) { return class AuthenticatedComponent extends React.Component { isAuthenticated() { return this.props.isAuthenticated; } render() {; return ( <div> { this.isAuthenticated === true ? <Component token={token} {...this.props} /> } </div> ); } }; } export default requireAuthentication;

Cuando accedo a los props del Component , obtengo props.token como undefined . ¿Hay alguna manera de pasar nuevos apoyos?

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

0

Supongo que necesita obtener el token para el componente si el componente tiene otro accesorio llamado isAuthenticated . Puedes hacerlo como a continuación.

 import React from "react"; export function requireAuthentication(Component) { return class AuthenticatedComponent extends React.Component { isAuthenticated() { return this.props.isAuthenticated; } render() { return ( <div> {this.props.isAuthenticated === true ? ( <Component token={"this_token_is_retrieved_by_requireAuthentication"} {...this.props} /> ) : ( <Component {...this.props} /> )} </div> ); } }; } const MyComp = requireAuthentication(({ token }) => { return <div>token: {token}</div>; }); export default function App() { return ( <div className="App"> <MyComp isAuthenticated={true} /> <MyComp isAuthenticated={false} /> </div> ); }

zona de pruebas de código

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!