Recompose: Q: How to access props in lifecycle hooks in `lifecycle` HOC

Created on 27 Sep 2017  路  9Comments  路  Source: acdlite/recompose

lifecycle({
  componentDidMount: () => {
    // How do i get prop here?
  }
})(Component)

Most helpful comment

The behavior in a arrow function is expected, because arrow functions have no binding of this.

All 9 comments

this.props

it seems this doesn't work when using arrow functions?

Is it working with alternative syntax for object methods? E.g.

lifecycle({
  componentDidMount() {
    this.props;
  }
})(Component)

EDIT: I've done a test locally, and it ought to work with the above syntax.

The alternative syntax worked for me, not the arrow fn. I'll test again but I'm pretty sure syntax was all I changed for it to work. Using es2015 and stage 2 in my babel config

you could try @hocs/with-lifecycle, works with arrow functions as well and doesn't depend on this:

withLifecycle(
  onDidMount: (props) => // ...
)

@deepsweet Any way to integrate that implementation into this project?

No way. Use search here for why.

No way. Use search here for why.

The behavior in a arrow function is expected, because arrow functions have no binding of this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Secretmapper picture Secretmapper  路  3Comments

robbporto picture robbporto  路  3Comments

gajus picture gajus  路  4Comments

istarkov picture istarkov  路  3Comments

isubasti picture isubasti  路  3Comments