DEV Community

Discussion on: Constructors in Functional Components With Hooks

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

In both cases where I illustrated useConstructor, it was defined above the App function.

Collapse
 
craigstowers profile image
Craig Stowers • Edited

Yeah it's where you defined it that i don't quite understand and it throws errors for me. "Const declarations' require an initialization value."

Your one has:

const useConstructor(callBack = () => {}) {
Enter fullscreen mode Exit fullscreen mode

Should it not be this? (which works)

const useConstructor = (callBack = () => {}) => {
Enter fullscreen mode Exit fullscreen mode

I'm not trying to nitpick... i'm just uncertain of my own knowledge and the ever changing landscape of javascript.

Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

Ahhh, yes. Good catch. I am missing the =>. Obviously, I didn't actually run these examples. I just typed them out. Thanks!