Skip to content

Changing Stateless components to default to function syntax instead of classes syntex #1197

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

Closed
wants to merge 3 commits into from

Conversation

ajaybeniwal
Copy link

I have changed some examples folder to default stateless components to more cleaner new syntax introduced in react 0.14 , If you like you can merge the changes.

@timdorr
Copy link
Member

timdorr commented Jan 13, 2016

Hmm, I'm kind of split on this. On the one hand, SFC's are cool and I'd love to see them used more. On the other hand, this raises the lowest common denominator (since they're so new and not as well-known as ES6 components) and are a tad slower (but that would be pre-optimization on our part).

I dunno, @gaearon what are you thoughts on this?

@gaearon
Copy link
Contributor

gaearon commented Jan 13, 2016

I'm up for changing all examples to functional components where possible.

However I don't see why we need react-stateless-wrapper I would like to avoid this dependency.

Also the comment is unnecessary, and there are some spacing inconsistencies.

@ajaybeniwal
Copy link
Author

HI @gaearon I added react-stateless-wrapper to make test cases pass because of the below mentioned issue
facebook/react#4972

@timdorr
Copy link
Member

timdorr commented Jan 13, 2016

I think I might take that as a ding against them right now. They should be testable without throwing in too many libraries.

@SimenB
Copy link
Contributor

SimenB commented Jan 13, 2016

The wrapper is 12 lines of code though (https://github.com/ngerritsen/react-stateless-wrapper/blob/master/react-stateless-wrapper.js), and stateless components is a recommended pattern from FB.

In an ideal world, most of your components would be stateless functions because these stateless components can follow a faster code path within the React core. This is the recommended pattern, when possible.

https://facebook.github.io/react/docs/reusable-components.html#stateless-functions

@sompylasar
Copy link

sompylasar commented Jan 13, 2016 via email

@badnorseman
Copy link
Contributor

Heads up! I've a complete repo with the todo example https://github.com/urbanvikingr/todo which I'm currently updating the docs with together @gaearon .
I'll transfer the source code to this repo soon.

@timdorr
Copy link
Member

timdorr commented Jan 27, 2016

Based on the work by the Dan's over in #1285, I'm going to close this in favor of the community effort going on over there. Feel free to join in!

@timdorr timdorr closed this Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants