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
Potentially confusing definition of "Higher-order component" in v1 docs #9226
Comments
@michaeljonathan -We use the `withStyles` higher-order component to inject an array of styles...
+We use the `withStyles()` higher-order component to inject an array of styles... Do you want to submit a pull-request? |
@oliviertassinari Imho, for newbies, that change doesn't make it less confusing at all. 😄 What about this: -We use the `withStyles` higher-order component to inject an array of styles...
+We use the higher-order component created by `withStyles()` to inject an array of styles... |
@leMaik Sounds way better ⛩ |
Can I make a PR?? @oliviertassinari. |
submitted the pull request #9235 |
Perhaps I'm confused, but to me |
ohh okay got it. @oliviertassinari Can I revert the changes??. |
@rosskevin Not if we refer to other libraries. Let's take the recompose documentation: https://github.com/acdlite/recompose/blob/master/docs/API.md.
I think that keeping the distinction will help people better understanding the concepts. |
This! 👍 |
So it seems that pretty much everyone agrees with this definition of a higher-order component:
I have to admit I thought of it that way, and apparently so did it's author? : But I agree that making the distinction is worthwhile, as it also explains the presence of the IFFE syntax that is perhaps unfamiliar to less experienced devs. (I recall having a "WTF?" moment the first time I saw If we fix it in the docs, we should probably fix the comment too, and also here: https://github.com/mui-org/material-ui/blob/v1-beta/docs/src/pages/getting-started/frequently-asked-questions.md#how-do-i-combine-the-withstyles-and-withtheme-hocs Edit: Also here: https://material-ui.com/customization/overrides/#overriding-with-class-names Secondly, I may have added to the docs confusion by including the words "We use the Would it be more correct to say that the resulting enhanced component injects the CSS? (At what point is the CSS actually injected?) Since they're all related it would be good pick them up in the associated PR. |
Hi @oliviertassinari,
Thank you for writing this library! It's definitely one of my favorite sources for learning how to write React components.
Minor question - I'm reading the CSS-in-JS section of the v1 docs, and correct me if I'm wrong, I think I see 2 definitions of "higher-order component"...
Definition 1
Definition 2
If I understood this correctly, the docs are saying that
withStyles
is a HOC that returns a HOC?I think the React docs on HOCs seem to prefer the 1st definition; preferring instead to call the returned object an
EnhancedComponent
.I'm not too worried about this personally, but I think this part of the docs may be confusing for those unfamiliar with the HOC term.
<aside>I don't personally resonate with the React official definition... I think it's confusing that React Components can be rendered but Higher-order Components can't; but this definition seems to be standard now so I've gotten used to it.</aside>
Thoughts?
The text was updated successfully, but these errors were encountered: