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

114
Views
¿Cómo puedo acceder al historial en mis componentes de reacción desde accesorios?

así que estoy tratando de obtener el objeto de historial de los accesorios en el componente en el que estoy trabajando y siempre muestra un error. Esta es la clase en la que estoy tratando de usar el objeto de historial.

 import React from 'react'; const Admin = (props) => { return ( <React.Fragment> <h1>Admin</h1> <button onClick={()=>this.props.history.push("/edit/new")} type="button" className="btn btn-primary btn-lg m-1"> Add </button> <table className="table"> <thead> <tr> <th scope="col">Name</th> <th scope="col">Price</th> <th></th> <th></th> </tr> </thead> <tbody> {props.prod.map(prod1 =>( <tr key ={prod1.id}> <td>{prod1.name}</td> <td>{prod1.price}</td> <td> <i onClick={()=>this.props.history.push(`/edit/${prod1.id}`) } className="fas fa-edit"></i> </td> <td> <span onClick={()=>props.delete(prod1)}> <i className ="fas fa-trash m-2" ></i> </span> </td> </tr> ))} </tbody> </table> </React.Fragment> );

}

exportar administrador predeterminado;

y app.jsx lo llamé en una ruta como esta

 <Route path="/admin" element = {<Admin prod = {this.state.Product} delete={this.deleteEntery} editing = {this.editElement} />}/>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No ha importado el enlace useHistory y ha declarado el historial usándolo.

Agregue esto para importar:

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

llama al historial de useHistory dentro de tu función usando el historial de variables:

 const history = useHistory()

Si tiene algún error de importación, use la última versión de React e instale 'react-router-dom' v5.2.0 usando este comando: npm install 'react-router-dom@v5.2.0'

about 4 years ago · Juan Pablo Isaza Report

0

En primer lugar, no está pasando 'historial' como accesorio al componente de administración, si quisiera usar el objeto de historial en su componente, simplemente necesitaría importarlo y usarlo (no es necesario pasarlo como accesorio).

 // Import it at the top of your file import { useHistory } from 'react-router-dom' // Call this hook inside your functional component, history variable has all the required properties const history = useHistory()
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!