├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── App.test.js ├── component │ ├── RulesHook.js │ ├── ShortCirEval.js │ ├── UseStateArray.js │ ├── UseStateObject.js │ ├── forms │ │ ├── basicForm.js │ │ ├── multipleInputs.js │ │ └── uncontrolled.js │ ├── myapp │ │ ├── about.js │ │ ├── home.js │ │ ├── index.js │ │ └── nav.js │ ├── shortCircuitEval.js │ ├── useContext │ │ ├── ComA.js │ │ ├── ComB.js │ │ └── ComC.js │ ├── useEffect │ │ ├── github │ │ │ ├── githubUsers.js │ │ │ ├── loading.js │ │ │ └── test.js │ │ ├── useEffect2.js │ │ ├── useEffectAPI.js │ │ ├── useEffects1.js │ │ └── useTitleCount.js │ └── useReducer │ │ ├── reducers.css │ │ └── useReducer.js ├── index.css ├── index.js ├── logo.svg ├── reportWebVitals.js └── setupTests.js └── yarn.lock /.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 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn 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 | ### `yarn 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 | ### `yarn 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 | ### `yarn 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": "thapareactapp", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "react": "^17.0.1", 10 | "react-dom": "^17.0.1", 11 | "react-icons": "^4.2.0", 12 | "react-router-dom": "^5.2.0", 13 | "react-scripts": "4.0.2", 14 | "web-vitals": "^1.0.1" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thapatechnical/reactHooks/0c9f9fe7057d87d61670fe2ddf9107ddef6b3f66/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 20 | 29 | React App 30 | 31 | 32 | 33 |
34 | 44 | 46 | 48 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thapatechnical/reactHooks/0c9f9fe7057d87d61670fe2ddf9107ddef6b3f66/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thapatechnical/reactHooks/0c9f9fe7057d87d61670fe2ddf9107ddef6b3f66/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/App.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-size: 90.5%; 3 | } 4 | 5 | body { 6 | min-height: 100vh; 7 | width: 100vw; 8 | background-color: #34495e; 9 | /* display: flex; 10 | justify-content: center; 11 | align-items: center; 12 | flex-direction: column; */ 13 | color: aliceblue; 14 | font-family: "Raleway", sans-serif; 15 | } 16 | 17 | .App { 18 | text-align: center; 19 | } 20 | 21 | .App-link { 22 | color: #8be3fb; 23 | } 24 | 25 | /* div { 26 | display: flex; 27 | justify-content: center; 28 | align-items: center; 29 | flex-direction: column; 30 | } */ 31 | 32 | p { 33 | font-size: 4rem; 34 | } 35 | 36 | h1 { 37 | font-size: 7rem; 38 | text-transform: capitalize; 39 | } 40 | 41 | .h1style { 42 | min-width: 20rem; 43 | width: 60rem; 44 | padding: 2rem 2rem; 45 | background-color: azure; 46 | color: #2980b9; 47 | border-radius: 5rem; 48 | box-shadow: 0rem 2rem 2rem -1.5rem rgba(0, 0, 0, 0.5); 49 | margin-top: 2rem; 50 | text-align: center; 51 | } 52 | 53 | .btn, 54 | .btnInner { 55 | margin: auto; 56 | margin-top: 2rem; 57 | border: none; 58 | outline: none; 59 | padding: 1rem 3rem; 60 | background-color: #2980b9; 61 | color: aliceblue; 62 | cursor: pointer; 63 | border-radius: 1rem; 64 | font-size: 3rem; 65 | } 66 | 67 | .btnInner { 68 | background-color: #d12b54; 69 | padding: 0.7rem 1.5rem; 70 | font-size: 1.5rem; 71 | margin-left: 4rem; 72 | } 73 | 74 | /* .btn:hover { 75 | background-color: #136ca7; 76 | } */ 77 | 78 | form { 79 | background: cornflowerblue; 80 | padding: 2rem; 81 | border-radius: 1rem; 82 | outline: none; 83 | text-align: left; 84 | } 85 | 86 | form label { 87 | margin-top: 2rem; 88 | font-size: 1.5rem; 89 | text-align: left; 90 | text-transform: capitalize; 91 | } 92 | 93 | form input { 94 | min-width: 20rem; 95 | height: 2rem; 96 | border-radius: 0.5rem; 97 | font-size: 1.2rem; 98 | text-align: left; 99 | border: none; 100 | margin-top: 0.3rem; 101 | padding: 0.5rem; 102 | outline: none; 103 | } 104 | 105 | button[type] { 106 | border: none; 107 | padding: 0.4rem 1rem; 108 | text-align: center; 109 | margin-top: 1rem; 110 | font-family: "Raleway", sans-serif; 111 | border-radius: 0.3rem; 112 | cursor: pointer; 113 | outline: none; 114 | } 115 | 116 | button[type]:hover { 117 | background-color: darkblue; 118 | color: aliceblue; 119 | } 120 | 121 | .showDataStyle { 122 | min-width: 20rem; 123 | width: 60rem; 124 | min-height: 2rem; 125 | padding: 1rem; 126 | background: rgb(68, 116, 207); 127 | color: aliceblue; 128 | margin-top: 4rem; 129 | display: flex; 130 | justify-content: space-around; 131 | align-items: center; 132 | flex-direction: row; 133 | border-radius: 1rem; 134 | box-shadow: 0 1rem 1rem -0.8rem rgba(0, 0, 0, 0.5); 135 | } 136 | 137 | .showDataStyle p { 138 | font-size: 1.5rem; 139 | } 140 | 141 | .showDataStyle p:first-child { 142 | font-weight: bold; 143 | } 144 | 145 | /* body { 146 | background-color: #b3e5fc; 147 | border-radius: 10px; 148 | font-family: "Raleway", sans-serif; 149 | } 150 | 151 | h2 { 152 | text-align: center; 153 | margin: 20px 0; 154 | } 155 | 156 | .textLeft { 157 | text-align: left; 158 | } 159 | 160 | .loadingDiv { 161 | height: 100vh; 162 | display: grid; 163 | place-items: center; 164 | } 165 | 166 | .card { 167 | width: 450px; 168 | border: none; 169 | border-radius: 10px; 170 | background-color: #fff; 171 | margin: auto; 172 | } 173 | 174 | .image { 175 | min-width: 155px; 176 | margin-right: 20px; 177 | } 178 | 179 | .stats { 180 | background: #f2f5f8 !important; 181 | color: #000 !important; 182 | } 183 | 184 | .articles { 185 | font-size: 10px; 186 | color: #a1aab9; 187 | } 188 | 189 | .number1 { 190 | font-weight: 500; 191 | } 192 | 193 | .followers { 194 | font-size: 10px; 195 | color: #a1aab9; 196 | } 197 | 198 | .number2 { 199 | font-weight: 500; 200 | } 201 | 202 | .rating { 203 | font-size: 10px; 204 | color: #a1aab9; 205 | } 206 | 207 | .number3 { 208 | font-weight: 500; 209 | } */ 210 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './App.css'; 3 | import UseEffects1 from "./component/useEffect/useEffects1" 4 | import UseEffect2 from "./component/useEffect/useEffect2" 5 | import UseEffectAPI from "./component/useEffect/useEffectAPI" 6 | import Uncontrolled from "./component/forms/uncontrolled"; 7 | import UseReducer from "./component/useReducer/useReducer"; 8 | import ComA from "./component/useContext/ComA"; 9 | import Test from "./component/useEffect/github/test"; 10 | import Home from "./component/myapp/home"; 11 | 12 | const App = () => { 13 | 14 | // console.log(useState('thapa technical')); 15 | // let myfirstVal = useState('thapa')[0]; 16 | // console.log(myfirstVal); 17 | 18 | // var val = 'thapa technical'; 19 | 20 | // const [myName, setMyName] = useState('thapa techncial Subs'); 21 | 22 | // const changeName = () => { 23 | // // val = "vinod thapa"; 24 | // // console.log(val); 25 | // let val = myName; 26 | 27 | // (val === 'thapa techncial Subs') ? 28 | // setMyName('vinod thapa') : setMyName('thapa techncial Subs'); 29 | 30 | // console.log(myName); 31 | return () 32 | } 33 | 34 | export default App 35 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/component/RulesHook.js: -------------------------------------------------------------------------------- 1 | // 1: Always write it inside the component or function 2 | // 2: Component name must be PascalCase (first letter should be uppercase) 3 | // 3: we can directly import or we can directly write it using React.hookName. 4 | // 4: Don’t call Hooks inside loops, conditions, or nested functions. 5 | 6 | import React from 'react' 7 | 8 | const RulesHook = () => { 9 | const [myName, setMyName] = React.useState('Vinod technical'); 10 | return ( 11 |
12 |

{ myName }

13 |
14 | ) 15 | } 16 | export default RulesHook 17 | -------------------------------------------------------------------------------- /src/component/ShortCirEval.js: -------------------------------------------------------------------------------- 1 | // import React, {useState} from 'react' 2 | 3 | // const ShortCirEval = () => { 4 | // const [demo, setDemo] = useState(""); 5 | // return ( 6 | //
7 | //

{demo || 8 | // <> 9 | //

{setDemo("Mast")}

10 | //

you can do anything

11 | // 12 | // } 13 | 14 | 15 | //

{ demo && "vinod" }

16 | //
17 | // ) 18 | // } 19 | 20 | // export default ShortCirEval 21 | 22 | // You can uncomment it and then use ok 23 | -------------------------------------------------------------------------------- /src/component/UseStateArray.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from 'react' 2 | 3 | const UseStateArray = () => { 4 | 5 | const myBioData = [ 6 | { 7 | id:0, myName:"vinod", age:26 8 | }, { 9 | id:1, myName:"thapa", age:27 10 | }, { 11 | id:2, myName:"technical", age:27 12 | } 13 | ] 14 | 15 | const [myArray, setmyArray] = useState(myBioData); 16 | 17 | const clearArray = () => { 18 | setmyArray([]); 19 | } 20 | 21 | const removeElem = (id) => { 22 | // alert(id);\ 23 | const myNewArray = myArray.filter((curElem) => { 24 | return curElem.id !== id; 25 | }) 26 | 27 | setmyArray(myNewArray); 28 | } 29 | 30 | return ( 31 | <> 32 | { 33 | myArray.map((curElm) => { 34 | 35 | return ( 36 | 37 |

Name: 38 | {curElm.myName} & Age: {curElm.age} 39 | 40 |

41 | ); 42 | } ) 43 | } 44 | 45 | 46 | ) 47 | } 48 | 49 | export default UseStateArray 50 | -------------------------------------------------------------------------------- /src/component/UseStateObject.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | const UseStateObject = () => { 4 | const [myObject, setMyObject] = React.useState({ 5 | myName:"vinod thapa", myAge:27, degree:"MCS", rollNo: 55, channel:"thapa tecnical" 6 | }); 7 | 8 | const changeObject = () => { 9 | setMyObject({...myObject, myAge:26}); 10 | } 11 | 12 | return ( 13 |
14 |

Name: {myObject.myName} & Age: {myObject.myAge} 15 | & Degree: {myObject.degree}

16 | 17 |
18 | ) 19 | } 20 | 21 | export default UseStateObject 22 | -------------------------------------------------------------------------------- /src/component/forms/basicForm.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from 'react' 2 | 3 | const BasicForm = () => { 4 | const [email, setEmail] = useState(""); 5 | const [password, setPassword] = useState(""); 6 | 7 | const [allEntry, setAllEntry] = useState([]); 8 | 9 | const submitForm = (e) => { 10 | e.preventDefault(); 11 | 12 | if (email && password) { 13 | const newEntry = { id: new Date().getTime().toString(), email, password }; 14 | 15 | setAllEntry([...allEntry, newEntry]); 16 | console.log(allEntry); 17 | 18 | setEmail(""); 19 | setPassword(""); 20 | } else { 21 | alert("plz fill the data"); 22 | } 23 | 24 | } 25 | 26 | return ( 27 | <> 28 |
29 |
30 | 31 | setEmail(e.target.value)} 34 | /> 35 |
36 | 37 |
38 | 39 | setPassword(e.target.value)} 42 | /> 43 |
44 | 45 | 46 | 47 |
48 | 49 |
50 | { 51 | allEntry.map((curElem) => { 52 | const { id, email, password } = curElem; 53 | return ( 54 |
55 |

{email}

56 |

{password}

57 |
58 | ) 59 | }) 60 | } 61 |
62 | 63 | ) 64 | } 65 | 66 | export default BasicForm 67 | -------------------------------------------------------------------------------- /src/component/forms/multipleInputs.js: -------------------------------------------------------------------------------- 1 | import React,{useState} from 'react' 2 | 3 | const MultipleInputs = () => { 4 | 5 | const [userRegistration, setUserRegistration] = useState({ 6 | username: "", 7 | email: "", 8 | phone: "", 9 | password: "" 10 | }); 11 | 12 | const [records, setRecords] = useState([]); 13 | 14 | const handleInput = (e) => { 15 | const name = e.target.name; 16 | const value = e.target.value; 17 | console.log(name, value); 18 | 19 | setUserRegistration({ ...userRegistration, [name]: value }); 20 | } 21 | 22 | const handleSubmit = (e) => { 23 | e.preventDefault(); 24 | 25 | const newRecord = { ...userRegistration, id:new Date().getTime().toString() } 26 | console.log(records); 27 | setRecords([...records, newRecord]); 28 | console.log(records); 29 | 30 | setUserRegistration({ username:"", email: "", phone: "", password: "" }); 31 | } 32 | 33 | return ( 34 | <> 35 |
36 |
37 | 38 | 42 |
43 | 44 |
45 | 46 | 50 |
51 | 52 |
53 | 54 | 58 |
59 | 60 |
61 | 62 | 66 |
67 | 68 | 69 |
70 | 71 |
72 | { 73 | records.map((curElem) => { 74 | const { id, username, email, phone, password } = curElem; 75 | return ( 76 |
77 |

{username}

78 |

{email}

79 |

{phone}

80 |

{password}

81 |
82 | ) 83 | }) 84 | } 85 |
86 | 87 | ) 88 | } 89 | 90 | export default MultipleInputs 91 | -------------------------------------------------------------------------------- /src/component/forms/uncontrolled.js: -------------------------------------------------------------------------------- 1 | import React , {useState, useRef} from 'react' 2 | 3 | const Uncontrolled = () => { 4 | 5 | // it like a useState only and its preserve the value. NO rerender. DOM 6 | const luckyName = useRef(null); 7 | const[show, setShow] = useState(false); 8 | 9 | const submitForm = (e) => { 10 | e.preventDefault(); 11 | const name = luckyName.current.value; 12 | name === "" ? alert("plz fill the data") : setShow(true); 13 | } 14 | 15 | return ( 16 |
17 |
18 |
19 | 20 | 21 |
22 |
23 | 24 |
25 |

{ show ? `your lucky name is ${luckyName.current.value}` : ""}

26 |
27 | ) 28 | } 29 | 30 | export default Uncontrolled 31 | -------------------------------------------------------------------------------- /src/component/myapp/about.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { useLocation, useHistory } from "react-router-dom"; 3 | 4 | const Index = () => { 5 | const location = useLocation(); 6 | const history = useHistory(); 7 | 8 | return ( 9 |
10 |

Hello {location.pathname.replace("/", '')} page

11 | { 12 | location.pathname === '/about/thapa' ? 13 |

Hii, Thapa Good to see you again

: 14 |

Login to see your files

15 | } 16 | 17 | 21 | 22 |
23 | ) 24 | } 25 | 26 | export default Index 27 | -------------------------------------------------------------------------------- /src/component/myapp/home.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { BrowserRouter, Route } from 'react-router-dom'; 3 | import Nav from "./nav"; 4 | import About from "./about"; 5 | import Index from "./index"; 6 | 7 | 8 | const Home = () => { 9 | return ( 10 | 11 |