The current way to 'export default' using decorators in NextJS

160 views Asked by At

I have a NextJS app that I'm upgrading to the latest version to take advantage of SWC (compared to older versions that used Babel).

As it turns out NextJS's implementation isn't exactly the same since Babel was supporting the legacy decorator proposal. The comments from NextJS team haven't been helpful either, so I turn to StackOverflow as I can't seem to get the right syntax:

// Old Code
@connect( mapStateToProps, { followUser, unfollowUser } )
export default class FollowCTA extends Component {
}

According to the latest decorator proposal, "Class decorators come after export and default"

// New Code as per docs
export default 
@connect( mapStateToProps, { followUser, unfollowUser } )
class FollowCTA extends Component {
}

The above code however throws the following error where that component was being used:

Unhandled Runtime Error
ReferenceError: FollowCTA is not defined

What is the right way to continue using decorators in NextJS?

0

There are 0 answers