You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: challenges/foundation/05.md
+29-6Lines changed: 29 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,9 +42,9 @@ export function StarshipCard() {
42
42
```javascript
43
43
// Create a `./src/components/index.tsx`
44
44
45
-
importScreenContainerfrom'./ScreenContainer';
46
-
importOfflinefrom'./Offline';
47
-
importCardfrom'./Card';
45
+
importScreenContainerfrom"./ScreenContainer";
46
+
importOfflinefrom"./Offline";
47
+
importCardfrom"./Card";
48
48
49
49
export { ScreenContainer, Offline, Card };
50
50
```
@@ -55,11 +55,11 @@ From the another component, to import the files
55
55
56
56
```javascript
57
57
// with `export default Card`
58
-
importCardfrom'./components/Card';
58
+
importCardfrom"./components/Card";
59
59
60
60
// with export function Card() { ... }
61
61
// with exported index.tsx
62
-
import { Card } from'./components/Card';
62
+
import { Card } from"./components/Card";
63
63
```
64
64
65
65
### Named Function Vs. Arrow Function
@@ -80,14 +80,37 @@ function Card(){
80
80
81
81
Choose a solution and keep it concistent accross your stack.
82
82
83
+
### Implicit return vs. normal return
84
+
85
+
```javascript
86
+
// β function with implicit return
87
+
constItem= ({ title }) => (
88
+
<View>
89
+
<Text>{title}</Text>
90
+
</View>
91
+
);
92
+
93
+
// β function normal return
94
+
constItem2= ({ 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
+
83
106
### One more thing
84
107
85
108
There is a nice pattern to know: **renaming a component on the go**
0 commit comments