Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm looking at Reactjs code looking like this..

export default authenticatedApplication ({

  // a very long code

})(App);

What form is this called? export default name({...})(Class) I don't even know what to Google. The closest I could find is this explanation, but does not have the form of the code in question.

question from:https://stackoverflow.com/questions/65933630/what-export-form-is-this-called-export-default-name-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
95 views
Welcome To Ask or Share your Answers For Others

1 Answer

Any programming is about assembling pieces of a programming language to do what you want. You can't look at a large chuck of code and think "Oh this is a blank". You have to look at the pieces and how they work together.

So break it down:

  • authenticatedApplication is a variable containing a function
  • authenticatedApplication({}) calls that function passing it an argument
  • authenticatedApplication({})(App) takes the return value of calling that function (which must be another function) and calls it (passing it App as an argument)
  • export default authenticatedApplication({})() takes the return value of that function and makes it the default export for the module

The closest I could find is this explanation, but does not have the form of the code in question.

The MDN documentation does have that form:

export default expression;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...