javascript / beginner
Snippet
Implicit Return in Arrow Functions
If an arrow function only contains one statement, you can omit the 'return' keyword and the curly braces. Using parentheses () allows for a cleaner look when returning JSX.
snippet.js
javascript
1
2
3
4
5
const DoubleValue = ({ number }) => (<span>Result: {number * 2}</span>);// Instead of: { return <span>...</span> }
react
Breakdown
1
=> ( ... )
The parentheses automatically return the code inside without needing the 'return' keyword.