-
Notifications
You must be signed in to change notification settings - Fork 1.3k
add mount option to lifecycle #68
Comments
+1 for this issue. |
I've been thinking lately about removing |
Does this make sense to anyone else? Is |
Well, not exactly. For example, you can start some timers when component is mounted - note, not in constructor, as it will cause problems with server-side rendering. Or, my own case, with which I came to this issue - a print page. It looks like this: class PrintPage extends React.Component {
render() {
return (
<Content {...this.props} />
);
}
componentDidMount() {
window.print();
}
} With Sure, it's all a very edge cases. But they exist, and it's always nicely when there is a handy function which saves you from manually writing another boilerplate class =) |
Have a question about: What the idea to pass To get state access user can use Does something like this will not be enough? class Lifecycle extends React.Component {
internalObj_ = null
componentWillMount() {
this.internalObj_ = setup(props)
}
...otherLifeCycleEventsIfNeeded
componentWillUnmount() {
teardown(this.props, this.internalObj_)
}
render() {
return createElement(BaseComponent, {...this.props, ...this.internalObj_})
}
} |
Without |
My use case is just to load an SDK(braintree) during |
I've been using The downside is that it triggers on What are your thoughts on this? |
@dariocravero I use |
Useful:
|
voted for keeping agree with @RafalFilipek |
Here is simple way to intercept livecycle method calls: import { compose, toClass } from 'recompose';
const enhance = compose(
component => class extends toClass(component) {
componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value) {
// Do something, value has changed.
}
}
},
); Simply extend the given component in the compose chain, and do whatever you need there. |
Closed by #162. |
Add
mount
option tolifecycle
that calls your function duringcomponentDidMount
. This will allow use for isomorphic/universal apps when you only want things ran on client and not on server.Let me know what you think. I could probably get a PR in this week.
The text was updated successfully, but these errors were encountered: