├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── About.js
├── App.css
├── App.js
├── AuthContext.js
├── CartContext.js
├── Eight.js
├── Eighteen.js
├── Eleven.js
├── Fifteen.js
├── Five.js
├── Four.js
├── Fourteen.js
├── Home.js
├── LocalizationContext.js
├── Nine.js
├── Nineteen.js
├── NineteenComp.js
├── One.js
├── Seven.js
├── Seventeen.js
├── Six.js
├── Sixteen.js
├── Ten.js
├── ThemeContext.js
├── Thirteen.js
├── Thirty.js
├── Three.js
├── Twelve.js
├── Twenty.js
├── TwentyEight.js
├── TwentyFive.js
├── TwentyFour.js
├── TwentyNine.js
├── TwentyOne.js
├── TwentySeven.js
├── TwentySix.js
├── TwentyThree.js
├── TwentyTwo.js
├── Two.js
├── forRouter
├── About.jsx
├── Contact.jsx
└── Home.jsx
├── images
├── image1.jpg
├── image2.jpg
├── image3.jpg
└── image4.jpg
├── index.css
├── index.js
└── styles
├── Eighteen.css
└── Nineteen.css
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react30",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.17.0",
7 | "@testing-library/react": "^13.4.0",
8 | "@testing-library/user-event": "^13.5.0",
9 | "axios": "^1.6.0",
10 | "browserify-zlib": "^0.2.0",
11 | "react": "^18.2.0",
12 | "react-dom": "^18.2.0",
13 | "react-icons": "^4.11.0",
14 | "react-router-dom": "^6.16.0",
15 | "react-scripts": "5.0.1",
16 | "web-vitals": "^2.1.4"
17 | },
18 | "scripts": {
19 | "start": "react-scripts start",
20 | "build": "react-scripts build",
21 | "test": "react-scripts test",
22 | "eject": "react-scripts eject"
23 | },
24 | "eslintConfig": {
25 | "extends": [
26 | "react-app",
27 | "react-app/jest"
28 | ]
29 | },
30 | "browserslist": {
31 | "production": [
32 | ">0.2%",
33 | "not dead",
34 | "not op_mini all"
35 | ],
36 | "development": [
37 | "last 1 chrome version",
38 | "last 1 firefox version",
39 | "last 1 safari version"
40 | ]
41 | },
42 | "devDependencies": {
43 | "webpack-cli": "^5.1.4"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 | You need to enable JavaScript to run this app.
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/About.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect } from 'react'
2 |
3 | export default function About() {
4 |
5 | useEffect(()=> {
6 | document.title="ABOUT"
7 | },[]);
8 |
9 | return (
10 |
11 | About
12 |
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/src/App.css
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import One from './One'
3 | import Two from './Two'
4 | import Three from './Three'
5 | import Four from './Four'
6 | import Five from './Five'
7 | import Six from './Six'
8 | import Seven from './Seven'
9 | import Eight from './Eight'
10 | import Nine from './Nine'
11 | import Ten from './Ten'
12 | import Eleven from './Eleven'
13 | import Twelve from './Twelve'
14 | import Thirteen from './Thirteen'
15 | import Fourteen from './Fourteen'
16 | import Fifteen from './Fifteen'
17 | import Sixteen from './Sixteen'
18 | import Seventeen from './Seventeen'
19 | import Eighteen from './Eighteen'
20 | import Nineteen from './Nineteen'
21 | import NineteenComp from './NineteenComp'
22 | import { ThemeProvider } from './ThemeContext'
23 | import Twenty from './Twenty'
24 | import { CartProvider } from './CartContext'
25 | import TwentyOne from './TwentyOne'
26 | import TwentyTwo from './TwentyTwo'
27 | import TwentyThree from './TwentyThree'
28 | import TwentyFour from './TwentyFour'
29 | import { AuthProvider } from './AuthContext'
30 | import TwentyFive from './TwentyFive'
31 | import TwentySix from './TwentySix'
32 | import { LocalizationProvider } from './LocalizationContext'
33 | import TwentySeven from './TwentySeven'
34 | import TwentyEight from './TwentyEight'
35 | import TwentyNine from './TwentyNine'
36 | import Thirty from './Thirty'
37 |
38 | export default function App() {
39 |
40 | // const items = ['Item 1','Item 2','Item 3','Another Item','Another Item 2'];
41 | return (
42 |
43 | {/*
*/}
44 | {/*
*/}
45 | {/*
*/}
46 | {/*
*/}
47 | {/*
*/}
48 | {/*
*/}
49 | {/*
*/}
50 | {/*
*/}
51 | {/*
*/}
52 | {/*
*/}
53 | {/*
*/}
54 | {/*
*/}
55 | {/*
*/}
56 | {/*
*/}
57 | {/*
*/}
58 | {/* */}
59 | {/* */}
60 | {/* */}
61 | {/*
62 |
63 |
64 |
65 |
66 | */}
67 | {/*
68 |
69 | */}
70 |
71 | {/* */}
72 | {/* */}
73 | {/* */}
74 | {/*
75 |
76 | */}
77 |
78 | {/* */}
79 | {/*
80 |
81 | */}
82 |
83 |
84 | {/* */}
85 | {/* */}
86 |
87 | {/* */}
88 |
89 |
90 | )
91 | }
92 |
--------------------------------------------------------------------------------
/src/AuthContext.js:
--------------------------------------------------------------------------------
1 | import { createContext,useContext, useState } from "react";
2 |
3 | const AuthContext = createContext();
4 |
5 | export function AuthProvider({children}){
6 |
7 | const[user,setUser] = useState(null);
8 |
9 | const login = (userData) => {
10 | setUser(userData)
11 | }
12 |
13 | const logout = ()=>{
14 | setUser(null)
15 | }
16 |
17 |
18 | return (
19 |
20 | {children}
21 |
22 | )
23 | }
24 |
25 | export function useAuth(){
26 | return useContext(AuthContext);
27 | }
--------------------------------------------------------------------------------
/src/CartContext.js:
--------------------------------------------------------------------------------
1 | import { createContext, useContext, useReducer } from "react";
2 |
3 | const CartContext = createContext();
4 |
5 | export function CartProvider({children}){
6 |
7 | const initialState = {
8 | cartItems:[]
9 | }
10 |
11 |
12 | function cartReducer(state,action){
13 | console.log(state,action)
14 | switch(action.type){
15 | case 'ADD_TO_CART':
16 | return{
17 | ...state,
18 | cartItems:[...state.cartItems,action.payload]
19 | };
20 | case 'UPDATE_QUANTITY':
21 | return{
22 | ...state,
23 | cartItems:state.cartItems.map((item)=>item.id=== action.payload.id?{...item,quantity:action.payload.quantity}:item)
24 | };
25 |
26 | case 'REMOVE_FROM_CART':
27 | return{
28 | ...state,
29 | cartItems:state.cartItems.filter((item)=> item.id !== action.payload),
30 | };
31 | default:
32 | return state;
33 | }
34 | }
35 |
36 | const [cartState,cartDispatch] = useReducer(cartReducer,initialState);
37 |
38 | return {children}
39 | }
40 |
41 | export function useCart(){
42 | return useContext(CartContext);
43 | }
--------------------------------------------------------------------------------
/src/Eight.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Eight() {
4 |
5 | const [input,setInput] = useState('');
6 | const [todos,setTodos] = useState([]);
7 |
8 | const addTodo = () => {
9 | if(input.trim()!== ''){
10 | setTodos([...todos,input]);
11 | setInput('');
12 | }
13 | }
14 |
15 | const removeTodo = (index) => {
16 | const updatedTodos = todos.filter((_,i) => i!== index);
17 | setTodos(updatedTodos)
18 | }
19 |
20 |
21 | return (
22 |
23 |
setInput(e.target.value)}/>
24 |
Add
25 |
26 | {todos.map((todo,index)=>(
27 |
28 | {todo} removeTodo(index)}>Remove
29 |
30 | ) )}
31 |
32 |
33 |
34 | )
35 | }
36 |
--------------------------------------------------------------------------------
/src/Eighteen.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import './styles/Eighteen.css'
3 |
4 | export default function Eighteen() {
5 |
6 | const[isOpen,setIsOpen] = useState(false);
7 |
8 | const toggleMenu = () => {
9 | setIsOpen(!isOpen);
10 | }
11 |
12 | return (
13 |
14 |
15 | ☰
16 |
17 |
18 | Home
19 | About
20 | Services
21 | Contacts
22 |
23 |
24 | )
25 | }
26 |
--------------------------------------------------------------------------------
/src/Eleven.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default function Eleven() {
4 |
5 | let quotes = [
6 | " Avoid daydreaming about the years to come.","You are the most important person in your whole life.","Always be true to who you are, and ignore what other people have to say about you.","Always be true to who you are, and ignore what other people have to say about you.","Only demonstrate your strength when it’s really required.","Subscribe to Drop X Out"
7 | ];
8 |
9 | const randomIndex = Math.floor(Math.random()*quotes.length);
10 | const quote = quotes[randomIndex];
11 |
12 | return (
13 |
14 | {quote}
15 |
16 | )
17 | }
18 |
--------------------------------------------------------------------------------
/src/Fifteen.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Fifteen({items}) {
4 |
5 | const [searchTerm,setSearchTerm] = useState('');
6 |
7 | const filteredItems = items.filter((item) =>
8 | item.toLowerCase().includes(searchTerm.toLowerCase())
9 | )
10 |
11 | return (
12 |
13 |
setSearchTerm(e.target.value)}/>
14 |
15 | {filteredItems.map((item,index) => (
16 |
17 | {item}
18 |
19 | ))}
20 |
21 |
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/src/Five.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Five() {
4 |
5 | const [isToggled,setIsToggles] = useState(false);
6 |
7 | const handleToggle = () => {
8 | setIsToggles(!isToggled);
9 | }
10 |
11 | return (
12 |
13 |
14 |
15 |
16 |
{isToggled ?" On ":" Off"}
17 |
18 | )
19 | }
20 |
--------------------------------------------------------------------------------
/src/Four.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default function Four() {
4 |
5 | const items = ['Item1 ','Item2','Item3 ','Item4 ','Item5 ']
6 | return (
7 |
8 | {items.map((item,index)=>{
9 | return {item}
10 | })}
11 |
12 | )
13 | }
14 |
--------------------------------------------------------------------------------
/src/Fourteen.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 |
3 | export default function Fourteen() {
4 | const [weather,setWeather] = useState(null);
5 |
6 | useEffect(()=> {
7 | if(navigator.geolocation) {
8 | navigator.geolocation.getCurrentPosition((position) => {
9 | const latitude = position.coords.latitude;
10 | const longitude = position.coords.longitude;
11 |
12 | fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=53cbf6b7bd02a2df9591c91dca9a2b85
13 | `)
14 | .then((response)=>response.json())
15 | .then((data) => setWeather(data));
16 | })
17 | }
18 | },[])
19 |
20 | return (
21 |
22 | {weather ? (
23 |
24 |
Current weather
25 |
Temperature:{weather.main.temp}
26 |
Conditions:{weather.weather[0].description}
27 |
28 | ):(
29 |
30 | Loading .....
31 |
32 | )
33 | }
34 |
35 | )
36 | }
37 |
--------------------------------------------------------------------------------
/src/Home.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect } from 'react'
2 |
3 | export default function Home() {
4 |
5 | useEffect(()=> {
6 | document.title="HOME"
7 | },[]);
8 |
9 | return (
10 |
11 | Home
12 |
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/src/LocalizationContext.js:
--------------------------------------------------------------------------------
1 | import { createContext, useContext, useState } from "react";
2 |
3 | const LocalizationContext = createContext();
4 |
5 | export const useLocalization = ()=> {
6 | return useContext(LocalizationContext)
7 | }
8 |
9 | export function LocalizationProvider({children}){
10 |
11 | const [locale,setLocale] = useState('en');
12 |
13 | const localizedString ={
14 | en:{
15 | greeting:'Hello World!',
16 | welcome:'Welcome to my app.'
17 | },
18 | es:{
19 | greeting:'Hola mundo!',
20 | welcome:'Bienvenido a mi aplicacion'
21 | }
22 | };
23 |
24 | const translate = (key) => {
25 | return localizedString[locale][key]
26 | }
27 |
28 | return (
29 |
30 | {children}
31 |
32 | )
33 |
34 |
35 | }
--------------------------------------------------------------------------------
/src/Nine.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Nine() {
4 |
5 | const [backgroundColor,setBackgroundColor] = useState('yellow');
6 |
7 | const handleClick = () => {
8 | const newColor = backgroundColor === 'yellow' ? 'lightblue' : 'white';
9 | setBackgroundColor(newColor)
10 | }
11 |
12 | return (
13 |
20 | Click me to Change Color
21 |
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/src/Nineteen.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useTheme } from './ThemeContext'
3 |
4 | export default function Nineteen() {
5 |
6 | const {isDarkMode,toggleTheme} = useTheme();
7 |
8 | return (
9 |
10 |
11 |
12 | Dark Mode
13 |
14 |
15 | )
16 | }
17 |
--------------------------------------------------------------------------------
/src/NineteenComp.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useTheme } from './ThemeContext'
3 | import './styles/Nineteen.css'
4 |
5 | export default function NineteenComp() {
6 | const {isDarkMode} = useTheme();
7 | const themeClass = isDarkMode ? 'dark-theme' : 'light-theme';
8 |
9 | return (
10 |
11 |
This component uses selected theme
12 |
13 | )
14 | }
15 |
--------------------------------------------------------------------------------
/src/One.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default function One() {
4 | return (
5 |
6 | Hello World !
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/src/Seven.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 |
3 | export default function Seven() {
4 |
5 | const [time,setTime] = useState(60);
6 |
7 | useEffect(()=>{
8 | if(time>0){
9 | const timer = setTimeout(()=> setTime(time-1),1000);
10 | return ()=> clearTimeout(timer);
11 | }
12 | },[time])
13 |
14 | return (
15 |
16 | Time Left: {time} second
17 |
18 | )
19 | }
20 |
--------------------------------------------------------------------------------
/src/Seventeen.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Seventeen() {
4 |
5 | const [selectedColor,setSelectedColor] = useState('#000000');
6 |
7 | const handleChange = (e) => {
8 | setSelectedColor(e.target.value);
9 | }
10 |
11 |
12 | return (
13 |
19 | )
20 | }
21 |
--------------------------------------------------------------------------------
/src/Six.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react'
2 |
3 | export default function Six() {
4 |
5 | const [data,setData] = useState(null);
6 |
7 | useEffect(()=> {
8 | fetch('https://jsonplaceholder.typicode.com/posts/1')
9 | .then((response) => response.json())
10 | .then((json) => setData(json))
11 | },[])
12 | return (
13 |
14 | {
15 | data? (
16 |
17 |
Title: {data.title}
18 | Body: {data.body}
19 |
20 | ) : (
21 |
22 | Loading...
23 |
24 | )}
25 |
26 | )
27 | }
28 |
--------------------------------------------------------------------------------
/src/Sixteen.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Sixteen({items,itemsPerPage}) {
4 |
5 | const [currentPage,setCurrentPage] = useState(1);
6 |
7 | const indexOfLastItem = currentPage*itemsPerPage;
8 | const indexOfFirstItem = indexOfLastItem - itemsPerPage;
9 | const currentItems = items.slice(indexOfFirstItem,indexOfLastItem);
10 |
11 | const pageNumbers = [];
12 | for(let i=1;i<=Math.ceil(items.length /itemsPerPage);i++){
13 | pageNumbers.push(i)
14 | }
15 |
16 | return (
17 |
18 |
19 | {currentItems.map((item,index) => {
20 | return {item}
21 | })}
22 |
23 | {pageNumbers.map((number)=>(
24 |
setCurrentPage(number)}>
25 | {number}
26 |
27 | ))}
28 |
29 | )
30 | }
31 |
--------------------------------------------------------------------------------
/src/Ten.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { BrowserRouter, Link, Route, Routes } from 'react-router-dom'
3 | import Home from './forRouter/Home';
4 | import Contact from './forRouter/Contact';
5 | import About from './forRouter/About';
6 |
7 | export default function Ten() {
8 | return (
9 |
10 |
11 |
12 |
13 | Home
14 |
15 |
16 | Contact
17 |
18 |
19 | About
20 |
21 |
22 |
23 |
24 | }>
25 | }>
26 | }>
27 |
28 |
29 | )
30 | }
31 |
--------------------------------------------------------------------------------
/src/ThemeContext.js:
--------------------------------------------------------------------------------
1 | import { createContext, useContext, useState } from "react";
2 |
3 |
4 | const ThemeContext = createContext();
5 |
6 | const ThemeProvider = ({children}) => {
7 | const [isDarkMode,setIsDarkMode] = useState(false);
8 |
9 | const toggleTheme = ()=> {
10 | setIsDarkMode((prevMode) => !prevMode)
11 | };
12 |
13 | return (
14 |
15 | {children}
16 |
17 | );
18 | };
19 |
20 |
21 | const useTheme = () => {
22 | return useContext(ThemeContext);
23 | }
24 |
25 | export {useTheme,ThemeProvider}
--------------------------------------------------------------------------------
/src/Thirteen.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Thirteen() {
4 |
5 | const [email,setEmail] = useState('');
6 | const [password,setPassword] = useState('');
7 | const [isRegistered,setIsRegistered] = useState(false);
8 | const [isLoggedIn,setIsLoggedIn] = useState(false);
9 | const [users,setUsers] = useState([])
10 |
11 | const handleAuthentication = () => {
12 | if(isRegistered){
13 | //LogIn
14 | if(isRegistered){
15 | const user = users.find((u)=> u.email === email && u.password === password);
16 | if(user) {
17 | setIsLoggedIn(true);
18 | }
19 | else{
20 | alert('Login failed.Please check your credential')
21 | }
22 | }
23 | }
24 | else {
25 | //Register
26 | const newUser = {email,password};
27 | setUsers([...users,newUser]);
28 | localStorage.setItem('users',JSON.stringify([...users,newUser]));
29 | setIsLoggedIn(true);
30 | }
31 | }
32 | const handleLogout = () => {
33 | setIsLoggedIn(false);
34 | setEmail('');
35 | setPassword('');
36 | }
37 |
38 |
39 | return (
40 |
41 | {
42 | isLoggedIn ? (
43 |
44 |
45 | Welcome , {email}!
46 |
47 | Logout
48 |
49 | ) : (
50 |
51 |
{isRegistered ? 'Login' : 'Register'}
52 |
59 |
60 | {isRegistered ? "Dont have an account? Register now" : 'Already have an account? Log in!'}
61 |
62 |
setIsRegistered(!isRegistered)}>
63 | {isRegistered ?'Register':'Login'}
64 |
65 |
66 | )
67 | }
68 |
69 | )
70 | }
71 |
72 |
--------------------------------------------------------------------------------
/src/Thirty.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { BrowserRouter, Routes ,Route} from 'react-router-dom'
3 | import Home from './Home'
4 | import About from './About'
5 |
6 | export default function Thirty() {
7 | return (
8 |
9 |
10 |
11 | }>
12 | }>
13 | {/* */}
14 |
15 |
16 |
17 | )
18 | }
19 |
--------------------------------------------------------------------------------
/src/Three.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Three() {
4 |
5 | const [input,setInput] = useState('');
6 |
7 | return (
8 |
9 |
setInput(e.target.value)} />
10 |
User Input: {input}
11 |
12 | )
13 | }
14 |
--------------------------------------------------------------------------------
/src/Twelve.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Twelve() {
4 |
5 | const [file,setFile] = useState(null);
6 |
7 | const handleFileChange = (e) => {
8 | const selectedFile = e.target.files[0];
9 | setFile(selectedFile)
10 | }
11 |
12 | return (
13 |
14 |
15 | {file &&
}
16 |
17 | )
18 | }
19 |
--------------------------------------------------------------------------------
/src/Twenty.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useCart } from './CartContext'
3 |
4 | export default function Twenty() {
5 |
6 | const {cartState,cartDispatch}= useCart();
7 |
8 | const addToCart = (item) => {
9 | const existingCartItem = cartState.cartItems.find((cartItem)=> cartItem.id === item.id);
10 |
11 | if(existingCartItem){
12 | cartDispatch({type:'UPDATE_QUANTITY',payload:{id:item.id,quantity:existingCartItem.quantity+1}})
13 | }
14 | else{
15 | cartDispatch({type:'ADD_TO_CART',payload:{...item,quantity:1}})
16 | }
17 | }
18 |
19 |
20 | const updateQuantity =(itemId,quantity) => {
21 | if(quantity>0){
22 | cartDispatch({type:'UPDATE_QUANTITY',payload:{id:itemId,quantity}});
23 | }
24 | };
25 |
26 |
27 | const removeFromCart = (itemId) => {
28 | cartDispatch({type:'REMOVE_FROM_CART',payload:itemId})
29 | };
30 |
31 |
32 |
33 | const products = [
34 | {id:1,name:'Product A'},
35 | {id:2,name:'Product B'},
36 | {id:3,name:'Product C'}
37 | ]
38 | return (
39 |
40 |
Shopping Cart
41 | {cartState.cartItems.map((item)=> (
42 |
43 | {item.name} - {item.quantity}
44 | updateQuantity(item.id,item.quantity +1 )}>+
45 | updateQuantity(item.id,item.quantity -1 )}>-
46 | removeFromCart(item.id)}>Remove
47 |
48 | ))}
49 |
Product List
50 |
{
51 | products.map((product)=> (
52 |
53 | {product.name} addToCart(product)}> Add To Cart
54 |
55 | ))}
56 |
57 |
58 | )
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/src/TwentyEight.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function TwentyEight() {
4 |
5 | const [state,setState] = useState({
6 | count:0,
7 | text:'Hello World',
8 | isActive:true
9 | })
10 |
11 | function increamentCount () {
12 | setState({...state,count:state.count+1})
13 | }
14 |
15 | function changeText(){
16 | setState({...state,text:'Updated Text'})
17 | }
18 |
19 | function toggleActive(){
20 | setState({...state,isActive:!state.isActive})
21 | }
22 |
23 | return (
24 |
25 |
Multiple State Example
26 |
Count:{state.count}
27 |
Text:{state.text}
28 |
Active:{state.isActive ? 'YES' :'NO'}
29 |
30 |
Increment
31 |
Change Text
32 |
Toggle Active
33 |
34 | )
35 | }
36 |
--------------------------------------------------------------------------------
/src/TwentyFive.js:
--------------------------------------------------------------------------------
1 | import React, { useReducer, useState } from 'react'
2 |
3 | function boxReducer(state,action){
4 | switch(action.type){
5 | case 'MOVE':
6 | return {
7 | ...state,
8 | left:action.payload.left,
9 | top:action.payload.top
10 | };
11 | default:
12 | return state;
13 | }
14 | }
15 |
16 | export default function TwentyFive() {
17 |
18 | const [boxState,dispatch] = useReducer(boxReducer,{left:0,top:0});
19 | const [isDragging,setIsDragging] = useState(false);
20 | const[initialX,setInitialX] = useState(0);
21 | const[initialY,setInitialY] = useState(0);
22 |
23 |
24 | const handleMouseDown =(e) => {
25 | setIsDragging(true)
26 | setInitialX(e.clientX - boxState.left);
27 | setInitialY(e.clientY - boxState.top);
28 | }
29 |
30 | const handleMouseUp=(e) => {
31 | setIsDragging(false)
32 | }
33 |
34 | const handleMouseMove=(e) => {
35 | if(isDragging){
36 | const left = e.clientX -initialX;
37 | const top = e.clientY - initialY;
38 | dispatch({type:'MOVE',payload:{left,top}});
39 | }
40 | }
41 |
42 | return (
43 |
48 | Drag Me
49 |
50 | )
51 | }
52 |
--------------------------------------------------------------------------------
/src/TwentyFour.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useAuth } from './AuthContext'
3 |
4 | export default function TwentyFour() {
5 |
6 | const {user,login,logout} = useAuth();
7 |
8 | return (
9 |
10 |
User Authentication Example
11 | {
12 | user ? (
13 |
14 |
Welcome , {user.username}
15 |
Logout
16 |
17 | ): (
18 |
login({username:'user12345'})}>Login
19 | )
20 | }
21 |
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/src/TwentyNine.js:
--------------------------------------------------------------------------------
1 | import React, { useReducer } from 'react'
2 |
3 | const initialState = {
4 | currentImageIndex:0
5 | }
6 |
7 | const imageReducer = (state,action) => {
8 | switch (action.type){
9 | case 'NEXT_IMAGE':
10 | return {
11 | currentImageIndex: state.currentImageIndex +1
12 | };
13 | case 'PREVIOUS_IMAGE':
14 | return{
15 | currentImageIndex:state.currentImageIndex -1
16 | }
17 | default :
18 | return state
19 | }
20 | }
21 |
22 | const images = [
23 | 'https://cdn.marvel.com/content/1x/thorloveandthunder_lob_crd_04.jpg',
24 | 'https://wallpapers.com/images/hd/marvel-pictures-a8zq5u8qw3ega7cx.jpg',
25 | 'https://cdn.britannica.com/62/182362-050-BD31B42D/Scarlett-Johansson-Black-Widow-Chris-Hemsworth-Thor.jpg',
26 | 'https://upload.wikimedia.org/wikipedia/en/1/19/Marvel_Universe_%28Civil_War%29.jpg'
27 | ]
28 |
29 |
30 |
31 | export default function TwentyNine() {
32 |
33 | const [state,dispatch] = useReducer(imageReducer,initialState);
34 |
35 | const currentImage = images[state.currentImageIndex];
36 |
37 | return (
38 |
39 |
Image Gallery
40 |
41 |
42 |
43 |
44 | dispatch({type:'PREVIOUS_IMAGE'})}>Previous
45 | dispatch({type:'NEXT_IMAGE'})}>Next
46 |
47 |
48 | )
49 | }
50 |
--------------------------------------------------------------------------------
/src/TwentyOne.js:
--------------------------------------------------------------------------------
1 | import React, { useReducer } from 'react'
2 |
3 | function reducer(state,action){
4 | switch(action.type){
5 | case 'INCREMENT':
6 | return {count: state.count+1}
7 |
8 | case 'DECREMENT':
9 | return {count: state.count-1}
10 | case 'RESET':
11 | return {count: 0}
12 | default:
13 | return state;
14 |
15 | }
16 |
17 | }
18 |
19 | const TwentyOne = () => {
20 |
21 | const [state,dispatch] = useReducer(reducer,{count:0});
22 |
23 | return (
24 |
25 |
Counter App
26 |
Count:{state.count}
27 |
dispatch({type:'INCREMENT'})}>+
28 |
dispatch({type:'DECREMENT'})}>-
29 |
dispatch({type:'RESET'})}>Reset
30 |
31 | )
32 | }
33 |
34 | export default TwentyOne
35 |
--------------------------------------------------------------------------------
/src/TwentySeven.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios'
2 | import React, { useEffect, useState } from 'react'
3 |
4 | export default function TwentySeven() {
5 | const [data1,setData1] = useState([]);
6 | const [data2,setData2] = useState([]);
7 |
8 |
9 | useEffect(()=>{
10 | axios.get('https://jsonplaceholder.typicode.com/posts/1')
11 | .then(response => {
12 | setData1(response.data)
13 | }
14 | )
15 | .catch(error=> {
16 | console.error('Error',error);
17 | });
18 |
19 | axios.get('https://jsonplaceholder.typicode.com/posts/2')
20 | .then(response => {
21 | setData2(response.data)
22 | }
23 | )
24 | .catch(error=> {
25 | console.error('Error',error);
26 | });
27 |
28 | },[])
29 |
30 | console.log(data1,data2)
31 | return (
32 |
33 |
34 |
35 | )
36 | }
37 |
--------------------------------------------------------------------------------
/src/TwentySix.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { useLocalization } from './LocalizationContext'
3 |
4 | export default function TwentySix() {
5 |
6 | const {setLocale,locale,translate} = useLocalization();
7 | console.log(locale)
8 |
9 | const handleLocaleChange = (newLocale) => {
10 | setLocale(newLocale)
11 | }
12 | return (
13 |
14 |
{translate('greeting')}
15 | {translate('welcome')}
16 | handleLocaleChange('en')}>English
17 | handleLocaleChange('es')}>Espanol
18 |
19 | )
20 | }
21 |
--------------------------------------------------------------------------------
/src/TwentyThree.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useReducer } from 'react'
2 |
3 | const itemsPerPage = 5 ;
4 |
5 | const paginationReducer = (state,action) => {
6 | switch(action.type){
7 | case 'SET_CURRENT_PAGE':
8 | return {...state,currentPage:action.payload}
9 | case 'SET_TOTAL_ITEMS':
10 | return {...state,totalItem:action.payload}
11 | default:
12 | return state
13 | }
14 | }
15 |
16 | export default function TwentyThree() {
17 |
18 | const [paginationState,dispatch] = useReducer(paginationReducer,{
19 | currentPage:1,
20 | totalItem:0
21 | })
22 |
23 | const data = Array.from({length:25},(_,index)=> `Item ${index+1}`);
24 |
25 | useEffect(()=> {
26 | dispatch({type:'SET_TOTAL_ITEMS',payload:data.length})
27 | },[data]);
28 |
29 | const startIndex = (paginationState.currentPage-1)*itemsPerPage;
30 | const endIndex = startIndex + itemsPerPage;
31 |
32 | const displayedItems = data.slice(startIndex,endIndex);
33 |
34 |
35 | const handlePageClick = (newPage)=> {
36 | dispatch({type:'SET_CURRENT_PAGE',payload:newPage})
37 | }
38 |
39 | return (
40 |
41 |
Pagination Example
42 |
43 | {displayedItems.map((item,index)=> (
44 |
45 | {item}
46 |
47 | ))}
48 |
49 |
50 | handlePageClick(paginationState.currentPage -1)} disabled={paginationState.currentPage ===1}>Previous
51 | handlePageClick(paginationState.currentPage+1)} disabled={endIndex>=data.length}>Next
52 |
53 |
54 | )
55 | }
56 |
--------------------------------------------------------------------------------
/src/TwentyTwo.js:
--------------------------------------------------------------------------------
1 | import React, { useReducer, useState } from 'react'
2 |
3 | const taskReducer = (state,action) => {
4 | switch(action.type){
5 | case 'ADD_TASK':
6 | return [...state,{id:Date.now(),text:action.payload,completed:false}]
7 | case 'REMOVE':
8 | return state.filter((task)=> task.id!== action.payload);
9 | case 'TOGGLE_TASK':
10 | return state.map((task) => task.id === action.payload ? {...task,completed:!task.completed}:task)
11 | default:
12 | return state;
13 | }
14 | }
15 |
16 | export default function TwentyTwo() {
17 |
18 | const [tasks,dispatch] = useReducer(taskReducer,[]);
19 |
20 | const [taskText,settaskText] = useState('');
21 |
22 | const addTask = () => {
23 | dispatch({type:'ADD_TASK',payload:taskText});
24 | }
25 |
26 | return (
27 |
28 |
Todo List
29 |
settaskText(e.target.value)} placeholder='Add new Task'/>
30 |
Add
31 |
32 | {tasks.map((task)=>(
33 |
34 | dispatch({type:'TOGGLE_TASK',payload:task.id})}
37 | >
38 | {task.text}
39 |
40 | dispatch({type:'REMOVE',payload:task.id})}>REMOVE
41 |
42 | ))}
43 |
44 |
45 | )
46 | }
47 |
--------------------------------------------------------------------------------
/src/Two.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 |
3 | export default function Two() {
4 | const [count,setCount] = useState(0);
5 |
6 | return (
7 |
8 | setCount(count+1)}> +
9 | {count}
10 | setCount(count-1)}>-
11 |
12 | )
13 | }
14 |
--------------------------------------------------------------------------------
/src/forRouter/About.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default function About() {
4 | return (
5 |
6 | ABOUT
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/src/forRouter/Contact.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default function Contact() {
4 | return (
5 |
6 | CONTACT
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/src/forRouter/Home.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | export default function Home() {
4 | return (
5 |
6 | HOME
7 |
8 | )
9 | }
10 |
--------------------------------------------------------------------------------
/src/images/image1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/src/images/image1.jpg
--------------------------------------------------------------------------------
/src/images/image2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/src/images/image2.jpg
--------------------------------------------------------------------------------
/src/images/image3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/src/images/image3.jpg
--------------------------------------------------------------------------------
/src/images/image4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/src/images/image4.jpg
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Drop-X-Out/react-practice-30/b9587870f3d704bb8d33abf1cfe276eee23dd0b9/src/index.css
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 |
6 | const root = ReactDOM.createRoot(document.getElementById('root'));
7 | root.render(
8 |
9 |
10 |
11 | );
--------------------------------------------------------------------------------
/src/styles/Eighteen.css:
--------------------------------------------------------------------------------
1 | .menu{
2 | display: none;
3 | list-style: none;
4 | padding: 0;
5 | margin: 0;
6 | }
7 | .menu.open{
8 | display: block;
9 | }
10 |
11 | .menu-icon{
12 | display: block;
13 | cursor: pointer;
14 | }
15 | @media (max-width:768px) {
16 | .menu-icon {
17 | display: block;
18 | }
19 |
20 | .menu {
21 | display: none;
22 | background-color: #333;
23 | position: absolute;
24 | top: 40px;
25 | right:0;
26 | width: 100%;
27 | }
28 | .menu li{
29 | padding: 10px;
30 | color: #fff;
31 | }
32 | }
--------------------------------------------------------------------------------
/src/styles/Nineteen.css:
--------------------------------------------------------------------------------
1 | .light-theme{
2 | background-color: #fff;
3 | color: #333333;
4 | }
5 |
6 | .dark-theme{
7 | background-color: #333333;
8 | color: #fff;
9 | }
--------------------------------------------------------------------------------