How to access props from lifecycle? #356
Comments
@ChenLi0830 Same way. All methods just extend component class and use it context. It's not quite clean and will be deprecated some day. |
Thank you @TrySound, do you mean I can access the props using |
Yep |
@istarkov We need to update docs |
Please do not deprecate lifecycle! I use it quite often. |
It worked, thanks a lot @TrySound! |
it worked,thanks a lot @TrySound |
@nick121212 because |
Thanks @wuct , I somehow missed this fact and was struggling for 15 minutes %) |
I'm getting undefined on
Any thoughts? |
@shawnmmatthews Just use class. |
@TrySound, Thanks for the response. Just confirming you are saying just use a class on the markup component vs trying to handle this in the HOC |
For use lifecycle({
componentDidMount() { this.props.some /* YES */ }
// `this` is binded to wrapper class component
}) Instead of: lifecycle({
componentDidMount: () => { this.props.some /* NO */ }
}) Arrow function using parent's context. |
I agree with @TrySound, at that point is seems better just to use a class. |
The class would imply all the noise of binding "this" to all handlers + "this.state" in the constructor + props splicing in the render method though |
@LaloHao And how lifecycle HOC solves any of it? It's just a wrapper around class with all class problems. |
In the same sense any computer language solves the abstraction of writing
direct processor operations
El mié., 8 de ago. de 2018 12:27 PM, Bogdan Chadkin <
notifications@github.com> escribió:
… @LaloHao <https://github.com/LaloHao> And how lifecycle HOC solves any of
it? It's just a wrapper around class with all class problems.
https://github.com/acdlite/recompose/blob/master/src/packages/recompose/lifecycle.js
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#356 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADfzqkNO5L5NyaMjmRNzcHf6YmUbmR9gks5uOx-NgaJpZM4M6tG1>
.
|
So how do you access props using a stateless component? Found this package https://www.npmjs.com/package/@hocs/with-lifecycle |
@webberwang Basically like this:
|
Thanks for that, I forgot to clarify in the lifecycle block. But I did find this package that integrates nicely with recompose which does that |
In my current component, the lifecycle methods call methods in
props
. For example,Now I want to rewrite it using recompose's lifecycle as shown below, how do I access the
props
?The text was updated successfully, but these errors were encountered: