Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of using brackets inside an arrow function in React/Redux

Given the following react-redux code:

const TextListContainer = ({ items, actions }) => (
    <TextList items={items} actions={actions} />
)

Why are normal brackets used here instead of curly brackets?


To further illustrate my question:

NORMAL FUNCTION:

const someFn = something => {
    //...
}

BRACE STYLE FUNCTION:

const someFn = something => (
    //...
)

This style of code is copied from here: https://github.com/reactjs/redux/blob/master/examples/todomvc/src/containers/App.js

like image 575
Alex Avatar asked Dec 12 '25 13:12

Alex


1 Answers

() => something, where something doesn't start with {, returns something.

With () => {, { is interpreted as the start of a function body, so you have to explicitly return something. To get around this, e.g. if you wanted to return an object, you can use (:

() => ({ some object })

Using it in other situations is a question of consistency.

like image 75
Tom Fenech Avatar answered Dec 14 '25 03:12

Tom Fenech