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

230
Views
pasar la función de envío a otra propiedad de instancia como devolución de llamada para ejecutar más tarde

Lo siento por el pseudocódigo. Piensa que el problema se puede entender así. Trabajando en un ejemplo reproducible.

Considere el siguiente pseudocódigo:

Foo de clase:

 let fooInstance = null class Foo() { constructor(){ fooInstance = this; this.fooCallback = null // property to assign callback } static getInstance() { return fooInstance } callbackExecutor() { if (this.fooCallback) // callback always null here even the assignment is ok in the component this.fooCallback(); } }

Componente React-Redux:

 import { argumentFunc } from 'src/argumentFunc' class MyComponent extends Component { constructor(props) { ... } componentDidUpdate(prevProps, prevState) { const foo = Foo.getInstance() if (whateverCond) { // callback assignment to instance. this.props.argumentFunc() works if called here foo.fooCallback = this.props.argumentFunc(); } } } ... const mapDispatchToProps = (dispatch) => ({ argumentFunc: () => dispatch(argumentFunc()), }) export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)

Asigno la devolución de llamada a la instancia, pero luego en callbackExecutor , this.fooCallback es nulo.

Lo intenté:
foo = this.props.argumentFunc();
foo = this.props.argumentFunc;
foo = () => this.props.argumentFunc();
foo = () => this.props.argumentFunc;

¿Cómo puedo pasar una devolución de llamada a la instancia ( fooInstance ) para que se llame más tarde dentro de los métodos de instancia de clase ( callbackExecutor() )?

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

0

Has probado:

 foo.getInstance().fooCallback = this.props.argumentFunc.bind(this)
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!