Skip to content

Commit 4446460

Browse files
committed
add: day16 notes and examples
1 parent ef6907f commit 4446460

File tree

10 files changed

+142
-1
lines changed

10 files changed

+142
-1
lines changed

Notes/day16.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// 17 - Dec - 2024
2+
3+
// conditional rendering and its examples

ReactByPrasadSir/src/App.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import JsxIntro from './components/01_jsxIntro/JsxIntro.jsx'
66
import ClassBasedCompIntro from './components/02_typesOfComponents/02_classBasedComp/ClassBasedCompIntro.jsx'
77
import HooksIntro from './components/03_hooks/HooksIntro.jsx'
88
import PropsIntro from './components/04_props/PropsIntro.jsx'
9+
import ConditionalRenderingIntro from './components/05_conditionalRendering/ConditionalRenderingIntro.jsx'
910

1011
function App() {
1112

@@ -27,7 +28,10 @@ function App() {
2728
{/* <HooksIntro/> */}
2829

2930
{/* ============ hooks ============ */}
30-
<PropsIntro/>
31+
{/* <PropsIntro/> */}
32+
33+
{/* ============ Conditional Rendering ============ */}
34+
<ConditionalRenderingIntro/>
3135
</>
3236
)
3337
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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

0 commit comments

Comments
 (0)