Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

LifeCycle: ComponentDidMount Example #264

Closed
brunobraga95 opened this issue Oct 28, 2016 · 8 comments
Closed

LifeCycle: ComponentDidMount Example #264

brunobraga95 opened this issue Oct 28, 2016 · 8 comments

Comments

@brunobraga95
Copy link

Anyone could give a precise example of how I can use lifecycle? I need to use ComponentDidMount and access the DOM, I know it is not a good practice but it is the only option I have. I also with all due respect, would like to advice recompose team to improve the documentation. As a beginner with react, I find it kind of hard to understand the methods without examples and etc.

thanks

@istarkov
Copy link
Contributor

Hi,
it's an open source project and if you think that documentation needs to be updated - please welcome.

For examples in any project you can use tests sources - all of them are good examples.
And just source code.

Most recompose methods are simple and small, in current case this is the source of lifecycle.
Almost no logic as you could see. Almost nothing to write in documentation :-)

@bholloway
Copy link

bholloway commented Oct 31, 2016

@istarkov I hope there are contributors that can help. @brunobraga95 and I are trying to learn and, by definition, are not in a position to generate such documentation... Maybe in time.

The source code for lifecycle does not help unless you understand the components/utilities it leverages: createEagerFactory -> createEagerElement -> createEagerElementUtil.

I do like how clean this makes the implementation. However while these lower-level components are simple they are abstractions, and it is not clear at first glance what they are doing. It would be nice to document in a how it works section, or at least have a comment block for these components.

Given that I agree that you could look at the lifecycle code and see what it is doing.

EDIT - I can see some discussion in this the performance docs. However I think most of the 'should I use this' is better termed 'how-it-works'. This library is good stuff: assume that people do want to use it and front-focus their learning.

@bholloway
Copy link

It looks like the lifecycle wrapped component will always re-render. So it needs to be composed with shouldUpdate() HOC or implement similar in its own spec.

I'm guessing this is the general philosophy? - All these components are small building blocks that attend to separate concerns, and you need to compose() them.

I think that is a big positive and is worth mentioning at the top of the API docs. It has definite implications on how people should approach things.

@istarkov
Copy link
Contributor

About re-renders,
In most cases you should not avoid re-renders,
React is fast enough to work without all that shouldComponentUpdate.

I see that people overuse optimisations, using them everywhere by default without any sense.
Having my experience any custom shouldComponentUpdate (by custom I mean that it's not just shallowEqual compare) will become a problem (bug) in the future.

About philosophy
Hard to translate, but isn't that already mentioned at the top of documentation
https://github.com/acdlite/recompose/blob/master/docs/API.md#api

@istarkov
Copy link
Contributor

istarkov commented Oct 31, 2016

About docs ;-)
It's well known that documentation of any project can be improved, BTW we all have the excuses to not doing this.
You - that you are just learning and so not in a position to generate ...
Me - I have poor english skill so ...
Someone - All is fine why to change something
Someone else - Any reason to not doing this ;-)

@bholloway
Copy link

Thanks @istarkov. I've also been looking through some of the other issues. I like how there seems to be lots of discussion and assistance on this project. That is always more important than docs!

@wuct
Copy link
Contributor

wuct commented Oct 31, 2016

@bholloway Thanks for your input. I think we should document what is the eager element and what is it for, because, obviously, it's the first obstacle to get into the source code.

@wuct
Copy link
Contributor

wuct commented Feb 28, 2017

A PR will be welcome if anyone want to enhance this part of doc.

@wuct wuct closed this as completed Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants