Skip to content

Commit fecac6d

Browse files
committed
fix: πŸ› Add Implicit and normal return
βœ… Closes: #162
1 parent 5772d0a commit fecac6d

File tree

1 file changed

+29
-6
lines changed
  • challenges/foundation

1 file changed

+29
-6
lines changed

β€Žchallenges/foundation/05.mdβ€Ž

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export function StarshipCard() {
4242
```javascript
4343
// Create a `./src/components/index.tsx`
4444

45-
import ScreenContainer from './ScreenContainer';
46-
import Offline from './Offline';
47-
import Card from './Card';
45+
import ScreenContainer from "./ScreenContainer";
46+
import Offline from "./Offline";
47+
import Card from "./Card";
4848

4949
export { ScreenContainer, Offline, Card };
5050
```
@@ -55,11 +55,11 @@ From the another component, to import the files
5555

5656
```javascript
5757
// with `export default Card`
58-
import Card from './components/Card';
58+
import Card from "./components/Card";
5959

6060
// with export function Card() { ... }
6161
// with exported index.tsx
62-
import { Card } from './components/Card';
62+
import { Card } from "./components/Card";
6363
```
6464

6565
### Named Function Vs. Arrow Function
@@ -80,14 +80,37 @@ function Card(){
8080

8181
Choose a solution and keep it concistent accross your stack.
8282

83+
### Implicit return vs. normal return
84+
85+
```javascript
86+
// βœ… function with implicit return
87+
const Item = ({ title }) => (
88+
<View>
89+
<Text>{title}</Text>
90+
</View>
91+
);
92+
93+
// βœ… function normal return
94+
const Item2 = ({ name }) => {
95+
return (
96+
<View>
97+
<Text>{name}</Text>
98+
</View>
99+
);
100+
};
101+
```
102+
103+
The first function (Item) uses an implicit return, which is a shorter syntax suitable for single-expression functions.
104+
The second function (Item2) uses a normal return, which allows for more complex function bodies and explicit handling of the return value. It also gives the ability to include additional logic before returning the JSX elements.
105+
83106
### One more thing
84107

85108
There is a nice pattern to know: **renaming a component on the go**
86109

87110
```javascript
88111
// App.tsx
89112

90-
import { LoginScreen as App } from './src/screens/LoginScreen';
113+
import { LoginScreen as App } from "./src/screens/LoginScreen";
91114
export default App;
92115
```
93116

0 commit comments

Comments
Β (0)