Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Authentication Implementing Basic Authentication Set up User Registration

Is there any particular reason for using standard function syntax instead of the arrow one in HOC?

React docs use it too, instead of arrow syntax. I wonder why - is it because of potential complications with "this" keyword when using arrow or just because standard function syntax is convenient (with arrow you can't write export default const withContext = () => {}, so you have declare function before export default keyword)?

2 Answers

Steven Parker
Steven Parker
220,634 Points

Arrow functions do not create their own bindings to the "this" like conventional functions do. MDN suggests that "Arrow function expressions are ill suited as methods".

For more detains, see the MDN page on Arrow functions.

Thanks but I'm asking if is there any particular reason not to use arrow functions in React's HOC , not about general purpose of arrow functions.

Steven Parker
Steven Parker
220,634 Points

Understood, I was thinking the difference in behavior might be such a reason.