Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Authentication (2019) 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
231,184 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
231,184 Points

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