├── .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 | You need to enable JavaScript to run this app.
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 | removeElem(curElm.id)}> remove
40 |
41 | );
42 | } )
43 | }
44 | Clear
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 | Update
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 |
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 |
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 |
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 |
history.push('/index')}>
19 | Home Page
20 |
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 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | )
20 | }
21 |
22 | export default Home
23 |
--------------------------------------------------------------------------------
/src/component/myapp/index.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 | console.log(history);
9 | return (
10 |
11 |
Hello {location.pathname.replace("/", '')} page
12 |
15 | Go Back
16 |
17 |
18 | )
19 | }
20 |
21 | export default Index
22 |
--------------------------------------------------------------------------------
/src/component/myapp/nav.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { NavLink } from 'react-router-dom';
3 |
4 | const Nav = () => {
5 | return (
6 | <>
7 |
8 | Navbar
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | Home (current)
17 |
18 |
19 | About
20 |
21 |
22 |
23 | Dropdown
24 |
25 |
26 |
Action
27 |
Another action
28 |
29 |
Something else here
30 |
31 |
32 |
33 | Disabled
34 |
35 |
36 | {/*
*/}
40 |
41 |
42 | >
43 | )
44 | }
45 |
46 | export default Nav
47 |
--------------------------------------------------------------------------------
/src/component/shortCircuitEval.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thapatechnical/reactHooks/0c9f9fe7057d87d61670fe2ddf9107ddef6b3f66/src/component/shortCircuitEval.js
--------------------------------------------------------------------------------
/src/component/useContext/ComA.js:
--------------------------------------------------------------------------------
1 | import React, { createContext } from 'react'
2 | import ComB from "./ComB";
3 |
4 | const BioData = createContext();
5 |
6 | const ComA = () => {
7 | return (
8 |
9 |
10 |
11 | )
12 | }
13 | export default ComA
14 | export { BioData };
15 |
--------------------------------------------------------------------------------
/src/component/useContext/ComB.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ComC from "./ComC";
3 |
4 | const ComB = () => {
5 | return
6 | }
7 |
8 | export default ComB
9 |
--------------------------------------------------------------------------------
/src/component/useContext/ComC.js:
--------------------------------------------------------------------------------
1 | import React, {useContext} from 'react'
2 | import { BioData } from "./ComA";
3 |
4 | const Comc = ({ name }) => {
5 | const channelName = useContext(BioData);
6 | return Hello ComC { channelName }
7 | }
8 |
9 | export default Comc
10 |
11 | // consumer
--------------------------------------------------------------------------------
/src/component/useEffect/github/githubUsers.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { FcApproval } from "react-icons/fc";
3 | import { FaGithub } from "react-icons/fa";
4 |
5 | const githubUsers = ({users}) => {
6 | return (
7 |
8 |
List of GitHub Users
9 |
10 |
11 |
12 | {
13 |
14 | users.map((curElem) => {
15 |
16 | const { avatar_url, id, login, type } = curElem;
17 | return (
18 |
19 |
20 |
21 |
22 |
23 |
{login}
24 | {/*
{type } */}
25 |
26 |
27 | Articles 38
28 |
29 | Followers 980
30 |
31 | Rating 8.9
32 |
33 |
34 |
35 |
36 |
37 |
38 | )
39 | })
40 |
41 | }
42 |
43 |
44 |
45 |
46 | )
47 | }
48 |
49 | export default githubUsers
50 |
--------------------------------------------------------------------------------
/src/component/useEffect/github/loading.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 |
3 | const Loading = () => {
4 | return (
5 |
6 |
Loading...
7 |
8 | )
9 | }
10 |
11 | export default Loading
12 |
--------------------------------------------------------------------------------
/src/component/useEffect/github/test.js:
--------------------------------------------------------------------------------
1 | import React, {useState} from 'react'
2 | import useTitleCount from "../useTitleCount";
3 |
4 | const Test = () => {
5 |
6 | const [count, setCount] = useState(0);
7 |
8 | //* custom hook
9 | useTitleCount(count);
10 |
11 | console.log("Hello outside");
12 |
13 | return (
14 |
15 |
{count}
16 | setCount(count + 1)
18 | } >Click Test😀
19 |
20 | )
21 | }
22 |
23 | export default Test
24 |
--------------------------------------------------------------------------------
/src/component/useEffect/useEffect2.js:
--------------------------------------------------------------------------------
1 | //CleanUp function
2 |
3 | import React, {useState, useEffect} from 'react'
4 |
5 | const UseEffect2 = () => {
6 |
7 | const [widthCount, setWidthCount] = useState(window.screen.width);
8 |
9 | const actualWidth = () => {
10 | console.log(window.innerWidth);
11 | setWidthCount(window.innerWidth);
12 | }
13 |
14 | useEffect(() => {
15 | console.log("add event");
16 | window.addEventListener("resize", actualWidth);
17 |
18 | return () => {
19 | console.log("remove Event");
20 | window.removeEventListener("resize", actualWidth);
21 | }
22 | });
23 |
24 |
25 | return (
26 |
27 |
The actual size of the window is:
28 |
{widthCount}
29 |
30 | )
31 | }
32 |
33 | export default UseEffect2
34 |
35 |
--------------------------------------------------------------------------------
/src/component/useEffect/useEffectAPI.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react'
2 | import Loading from './github/loading';
3 | import GithubUsers from "./github/githubUsers";
4 |
5 | const UseEffectAPI = () => {
6 |
7 | const [users, setUsers] = useState([]);
8 | const [loading, setLoading] = useState(true);
9 |
10 | const getUsers = async () => {
11 | try {
12 | const response = await fetch('https://api.github.com/users');
13 | setLoading(false);
14 | setUsers(await response.json());
15 | } catch (error) {
16 | setLoading(false);
17 | console.log("my error is "+ error);
18 | }
19 | }
20 |
21 | useEffect(() => {
22 | getUsers();
23 | }, []);
24 |
25 | if (loading) {
26 | return
27 | }
28 |
29 | return (
30 | <>
31 |
32 | >
33 | )
34 | }
35 |
36 | export default UseEffectAPI
37 |
--------------------------------------------------------------------------------
/src/component/useEffect/useEffects1.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react'
2 | import useTitleCount from "./useTitleCount";
3 |
4 | const UseEffects1 = () => {
5 |
6 | const [count, setCount] = useState(0);
7 |
8 | // custom hook
9 | useTitleCount(count);
10 |
11 | console.log("Hello outside");
12 |
13 | return (
14 |
15 |
{count}
16 | setCount(count + 1)
18 | } >Click😀
19 |
20 | )
21 | }
22 |
23 | export default UseEffects1
24 |
--------------------------------------------------------------------------------
/src/component/useEffect/useTitleCount.js:
--------------------------------------------------------------------------------
1 | import {useEffect} from "react";
2 |
3 | const useTitleCount = (count) => {
4 | useEffect(() => {
5 | console.log("I am first one");
6 | if (count >= 1) {
7 | document.title = `Chats (${count})`
8 | } else {
9 | document.title = `Chats `
10 | }
11 | }, [count]);
12 | }
13 |
14 | export default useTitleCount;
15 |
--------------------------------------------------------------------------------
/src/component/useReducer/reducers.css:
--------------------------------------------------------------------------------
1 | .btnStylePosition {
2 | width: 200px;
3 | place-items: stretch;
4 | }
5 |
6 | .btnStylePosition button {
7 | padding: 5px 12px;
8 | }
9 |
--------------------------------------------------------------------------------
/src/component/useReducer/useReducer.js:
--------------------------------------------------------------------------------
1 |
2 | import React, { useReducer } from 'react'
3 | import './reducers.css';
4 |
5 | const initialState = 0;
6 |
7 | const reducer = (state, action) => {
8 | console.log(state, action);
9 | if (action.type === "INCREMENT") {
10 | return state + 1;
11 | }
12 | if (action.type === "DECREMENT") {
13 | return state - 1;
14 | }
15 | return state;
16 | }
17 |
18 | const UseReducer = () => {
19 |
20 | const [state, dispatch] = useReducer(reducer, initialState);
21 |
22 | return (
23 | <>
24 |
25 |
{state}
26 |
27 | dispatch({type: "INCREMENT"})}> Inc
28 | dispatch({type: "DECREMENT"})}> Dec
29 |
30 |
31 |
32 | >
33 |
34 | )
35 | }
36 | export default UseReducer
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | /* In JavaScript Reduce method :- The first and most important thing to understand about a reducer is that
48 | it will always only return one value. The job of a reducer is to reduce.
49 | That one value can be a number, a string, an array or an object,
50 | but it will always only be one. Reducers are really great for a lot of things,
51 | but they’re especially useful for applying a bit of logic to a
52 | group of values and ending up with another single result. */
53 |
54 | /* But in React useReducer having seen the way reduce fires a function against an initial value.
55 | It’s the same sort of concept, but returns two elements as an array,
56 | the current state and a dispatch function. */
57 | /*differences
58 | 1: Js reduce method returns only one value
59 | 1: react useReducer return two elements as an array */
60 |
61 |
62 |
63 | // import React, { useState } from 'react'
64 | // import './reducers.css';
65 |
66 | // const UseReducer = () => {
67 | // const [count, setCount] = useState(0);
68 | // return (
69 | // <>
70 | //
71 | //
{count}
72 | //
73 | // setCount(count + 1)}> Inc
74 | // setCount(count - 1)}> Dec
75 | //
76 |
77 | //
78 | // >
79 |
80 | // )
81 | // }
82 | // export default UseReducer
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want to start measuring performance in your app, pass a function
15 | // to log results (for example: reportWebVitals(console.log))
16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17 | reportWebVitals();
18 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------