Skip to content
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

Warn for all unsupported lifecycles in stateless Components #6926

Closed
gingur opened this issue May 31, 2016 · 8 comments
Closed

Warn for all unsupported lifecycles in stateless Components #6926

gingur opened this issue May 31, 2016 · 8 comments

Comments

@gingur
Copy link

gingur commented May 31, 2016

Example: https://jsfiddle.net/gingur/u0h2rjae/1/

When generating child context with a stateless Component, the context is not available to the children.

@gingur
Copy link
Author

gingur commented May 31, 2016

Apparently none of the Component lifecycle events are supported, if it is intended that context is also not supported then suggest a warning to be thrown when using a non-production build of React.

@jimfb
Copy link
Contributor

jimfb commented May 31, 2016

Yeah, a warning for all the lifecycles is probably a good idea.

@jimfb jimfb changed the title Support getChildContext in stateless Components Warn for all unsupported lifecycles in stateless Components May 31, 2016
@gingur
Copy link
Author

gingur commented May 31, 2016

@jimfb
Copy link
Contributor

jimfb commented May 31, 2016

Yeah, that sounds like a reasonable place to me. cc @spicyj for confirmation.

@sophiebits
Copy link
Collaborator

I don't think this makes much sense because the mental model is that these functions are called, not constructed – so the prototype shouldn't come into play at all. But I guess that's a reasonable place if we do want the warning.

@jimfb
Copy link
Contributor

jimfb commented May 31, 2016

Yeah, but we sort of violate the mental model with contextTypes and propTypes and related properties that get set on the function. I can see how someone could think they could add a lifecycle function in the same way. There really isn't any harm in adding a warning, and it might help people catch errors in their mental model.

@gingur
Copy link
Author

gingur commented May 31, 2016

If at a minimum childContextTypes could trigger a warning since contextTypes, propTypes and defaultProps are supported but do not require an additional prototype function such as getChildContext to be available.

@sophiebits
Copy link
Collaborator

Yeah, that makes sense. Let's start with childContextTypes and revisit if anyone else is confused after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants