-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Rule proposal: react/no-will-mount #1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I disagree; i think everything that's not initializing state belongs in Async requests in the constructor have the same issues; neither us often a problem in practice. I'm a strong -1. |
Wouldn't most async requests in practice set state on completion? From my POV the question here is if there are a reasonable number of developers considering putting asynchronous requests in I think the React docs imply this.
My understanding (which is very limited, so please correct me if I'm wrong) is that async rendering with fibers means that an async request might complete before mount and sometimes after (maybe the mount could even be aborted?). (I would be willing to implement this if I can be reasonably sure that it would be accepted.) |
Side effects in JS never belong in constructors. If React advises that, they are wrong. |
My quotation was a bit confusing, those were excerpts from different paragraphs. |
Indeed, fiber may change the timing of some of these things. But fiber isn't out yet, and if the issue is doing async things prior to the first render, then constructor vs componentWillMount has the same problem. In other words, I'm still not seeing a reason to discourage componentWillMount - you've only talked about async setStates initiated prior to mounting. |
tracking: facebook/react#7671 |
It seems like a significant number of React developers agree that using this method should be discouraged. If you do not agree it's of course fine to not use the rule. Are you opposed to (me?) adding the rule at all to this project? |
I'm not sure where you get "significant number" - that github issue is full of people who simply don't see a need for the method, with very very few claiming that its use should be discouraged. So yes, I'm opposed to adding the rule at all. |
Ok |
I'm not the only collaborator; this should remain open pending the others' thoughts. |
Given it's an official FB recommendation (quoted above)
It would make sense to have this as an optional linting rule. Certainly shouldn't be a recommended one but a lot of the core devs seem pro-deprecation and have mentioned that post-fiber it would make sense to examine the issue more. Most linting rules are completely subjective, this seems to at least be a reasonable suggestion for an optional rule. |
Afaik there's still active discussions going on with core devs about it; I don't believe they've made a compelling case. Note that Facebook doesn't server-render, and their position on |
Sure, there are plenty of active discussions about many things - including things where rules already exist in this package. That's what best practice debates are composed of 😄 My point is more - this kind of rule is a classic optional linting step feature. God knows there are existing rules in this package that I'm never going to turn on because they don't work for me or my projects. This rule would be no different to those. Side note: I extensively use server-rendering and honestly, the story there is not as complex as some in that discussion would make it. Though yes, there are complexities involved and for those components that must use cWM then perhaps turning the rule off makes sense - but that's good, as it requires intentionality. |
Indeed, your preference is clear. If the rule existed you'd not use it/turn it off. 👍 |
To clarify; my preference is to not include the rule, so that nobody is ever able to turn it on. |
this is a different context/discussion and a different rule, but now that React 16.3 is going to be deprecating |
It’s not yet possible to recommend alternatives for every use case, nor have they actually been deprecated yet. When React provides enough replacements for cWM etc, then we’ll definitely make linting rules to cover them. |
Generally, it would make sense to me to have a |
Oh that's a quite nice generalized rule, could even have a recommended/default set. |
This seems handled by #1750. |
There are few use cases for
componentWillMount
that cannot be handled in the constructor.It is a common mistake to put asynchronous requests in
componentWillMount
which could potentially cause hard to find errors.The text was updated successfully, but these errors were encountered: