Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
Confused about return value in arrow function?

I found this code in one a tutorial.

const renderApp = (Component) =>
  render(
    <Provider store={store}>
        <AppContainer>
          <Component />
        </AppContainer>
    </Provider>,
    document.getElementById('root')
  );

My question is shouldnt the return value be wrapped in braces? because arrow functions return whats next to => if nothing is metnioned ?

const renderApp = (Component) => (
  render(
    <Provider store={store}>
        <AppContainer>
          <Component />
        </AppContainer>
    </Provider>,
    document.getElementById('root')
  );
)

shouldn't it have braces to wrap contents ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The right hand side of an arrow function can be either:

  • A block
    • delimited with { and } (which are braces)
    • which returns whatever the return statement in the block says
  • An expression
    • which returns whatever the result of evaluating the expression is

You need to wrap the expression with parenthesis (( and )) if it is an object literal because object literals are delimited with braces.

() => { foo: 123, bar: 456 }; // This is an error

If you wrote the above, the { and } would be interpreted as a block and not an expression to create an object.

() => ({ foo: 123, bar: 456 });

Adding parenthesis tells the JS parser that it is an expression and not a block.

Since your expression doesn't start with a {, it won't be treated as a block so there is no need for parenthesis.


The first code snippet, after "=>" its empty, wont JS compiler insert ; and end it there ?

No. Automatic semi-colon insertion only occurs in places which could be the end of something. It won't happen in after => because there must be something on the right-hand side of =>.

about 4 years ago · Juan Pablo Isaza Report

0

There's no need to wrap it within braces because a single line statement gets returned implicitly. You however can do it yourself, it isn't incorrect, just that it's a bit of syntactic sugar

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!