question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Potentially confusing definition of "Higher-order component" in v1 docs

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

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

We use the withStyles higher-order component to inject an array of styles…

Definition 2

API withStyles(styles, [options]) => Higher-order Component

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
oliviertassinaricommented, Nov 20, 2017

Perhaps I’m confused, but to me withStyles is the HOC.

@rosskevin Not if we refer to other libraries. Let’s take the recompose documentation: https://github.com/acdlite/recompose/blob/master/docs/API.md.

a higher-order component (HOC) refers to a function that accepts a single React component and returns a new React component.

Most Recompose helpers are functions that return higher-order components:

I think that keeping the distinction will help people better understanding the concepts.

2reactions
pajaydevcommented, Nov 19, 2017

Can I make a PR?? @oliviertassinari.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >
Higher-Order Components In React - Smashing Magazine
A higher-order component (HOC) is an advanced element for reusing logic in React components. Components take one or more components as arguments ......
Read more >
React Higher Order Components in depth | by franleplant
Component being returned. The “wraps” part of the definition is intentionally vague because it can mean one of two things: Props Proxy: The...
Read more >
Introduction to Higher-Order Components in React by example
React's Higher Order Component is a pattern that stems from React's nature that privileges composition over inheritance.
Read more >
Docs • Svelte
Complete documentation for Svelte.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found