File tree 10 files changed +142
-1
lines changed
components/05_conditionalRendering
10 files changed +142
-1
lines changed Original file line number Diff line number Diff line change
1
+ // 17 - Dec - 2024
2
+
3
+ // conditional rendering and its examples
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import JsxIntro from './components/01_jsxIntro/JsxIntro.jsx'
6
6
import ClassBasedCompIntro from './components/02_typesOfComponents/02_classBasedComp/ClassBasedCompIntro.jsx'
7
7
import HooksIntro from './components/03_hooks/HooksIntro.jsx'
8
8
import PropsIntro from './components/04_props/PropsIntro.jsx'
9
+ import ConditionalRenderingIntro from './components/05_conditionalRendering/ConditionalRenderingIntro.jsx'
9
10
10
11
function App ( ) {
11
12
@@ -27,7 +28,10 @@ function App() {
27
28
{ /* <HooksIntro/> */ }
28
29
29
30
{ /* ============ hooks ============ */ }
30
- < PropsIntro />
31
+ { /* <PropsIntro/> */ }
32
+
33
+ { /* ============ Conditional Rendering ============ */ }
34
+ < ConditionalRenderingIntro />
31
35
</ >
32
36
)
33
37
}
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import ConditionalEx1 from './examples/ConditionalEx1'
3
+ import TaskIntro from './Task/TaskIntro'
4
+
5
+ const ConditionalRenderingIntro = ( ) => {
6
+ return (
7
+ < div >
8
+ { /* <ConditionalEx1/> */ }
9
+ < TaskIntro />
10
+ </ div >
11
+ )
12
+ }
13
+
14
+ export default ConditionalRenderingIntro
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ const About = ( props ) => {
4
+ return (
5
+ < div >
6
+ about page
7
+ </ div >
8
+ )
9
+ }
10
+
11
+ export default About
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ const Contact = ( props ) => {
4
+ return (
5
+ < div >
6
+ contact page
7
+ </ div >
8
+ )
9
+ }
10
+
11
+ export default Contact
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ const Homepage = ( props ) => {
4
+ return (
5
+ < div >
6
+ < h1 > homepage</ h1 >
7
+ < p > welcome { props . props } </ p >
8
+ </ div >
9
+ )
10
+ }
11
+
12
+ export default Homepage
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import Homepage from './Homepage' ;
3
+ import Contact from './Contact' ;
4
+ import About from './About' ;
5
+ import PageNotFound from '../examples/PageNotFound' ;
6
+
7
+ const TaskIntro = ( ) => {
8
+ let userName = prompt ( 'Enter username' ) ;
9
+ let pageName = prompt ( 'Enter page name u want to visit (homepage, contact or about)' ) ;
10
+ switch ( pageName ) {
11
+ case 'homepage' :
12
+ return < Homepage prop = { userName } />
13
+ // break;
14
+ case 'contact' :
15
+ return < Contact prop = { userName } />
16
+ // break;
17
+ case 'about' :
18
+ return < About prop = { userName } />
19
+ // break;
20
+ default :
21
+ return < PageNotFound />
22
+ // break;
23
+ }
24
+ }
25
+
26
+ export default TaskIntro
27
+
28
+
29
+ // break in new react version
Original file line number Diff line number Diff line change
1
+ import Home from './Home' ;
2
+ import PageNotFound from './PageNotFound' ;
3
+
4
+ const ConditionalEx1 = ( ) => {
5
+ // localStorage.setItem('username','xyz@123')
6
+ let uName = localStorage . getItem ( 'username' )
7
+ console . log ( uName ) ;
8
+ if ( uName == 'xyz@12' ) {
9
+ return < Home />
10
+ } else {
11
+ return < PageNotFound />
12
+ }
13
+
14
+ }
15
+
16
+ export default ConditionalEx1
17
+
18
+ // 10-12 room 6/3/2
19
+ // room 3
20
+
21
+ // task
22
+ // `
23
+ // - uname+pagename take input using prompt
24
+ // switch case(pagename == home){
25
+ // <Home prop={uname}/>
26
+ // }
27
+ // default ===> page not found call kro
28
+
29
+
30
+
31
+ // homepage
32
+ // ________________
33
+ // Home page
34
+ // welcome
35
+ // username
36
+ // `
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ const Home = ( ) => {
4
+ return (
5
+ < div >
6
+ Welcome to Homepage
7
+ </ div >
8
+ )
9
+ }
10
+
11
+ export default Home
Original file line number Diff line number Diff line change
1
+ import React , { useState } from 'react'
2
+
3
+ const PageNotFound = ( ) => {
4
+ let [ theme , setTheme ] = useState ( 'dark' )
5
+ return < div >
6
+ < h1 style = { theme == 'light' ?{ } :{ backgroundColor :'black' , color : 'white' } } > Page Not Found</ h1 >
7
+ </ div >
8
+ }
9
+
10
+ export default PageNotFound
You can’t perform that action at this time.
0 commit comments