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
() => 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With