File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
courses/react-js/begginer-level/building-your-first-react-app Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ // Define a functional component using JSX
1
4
const MyComponent = ( ) => {
5
+ // Define some variables to use in JSX expressions
2
6
const name = "Ajay" ;
3
7
const isLoggedIn = true ;
4
8
const fruits = [ "apple" , "banana" , "orange" ] ;
5
9
10
+ // JSX component rendering
6
11
return (
7
12
< div >
8
13
< h1 > Hello, { name } !</ h1 >
9
14
15
+ { /* Embedding expressions */ }
10
16
< p > { isLoggedIn ? "You are logged in" : "Please log in" } </ p >
11
17
18
+ { /* Defining attributes */ }
12
19
< img src = "https://github.com/ajay-dhangar.png" alt = "Ajay" style = { { width : "100px" , borderRadius : "50%" } } />
13
20
21
+ { /* Conditionally render elements */ }
14
22
{ isLoggedIn && < p > Welcome back, { name } !</ p > }
15
23
24
+ { /* Mapping over arrays */ }
16
25
< ul >
17
26
{ fruits . map ( ( fruit , index ) => (
18
27
< li key = { index } > { fruit } </ li >
19
28
) ) }
20
29
</ ul >
21
30
31
+ { /* Compose components */ }
22
32
< Button text = "Click me" onClick = { ( ) => alert ( "Button clicked!" ) } />
23
33
</ div >
24
34
) ;
You can’t perform that action at this time.
0 commit comments