├── .gitattributes ├── LICENSE ├── README.md ├── episode-10 ├── 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 │ ├── Pages │ ├── Contact.js │ ├── Home.js │ ├── Nav.js │ └── Profile.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-11 ├── 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 │ ├── Components │ └── submitForm.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-12 ├── 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 │ ├── Cat.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ ├── setupTests.js │ ├── useCount.js │ ├── useGetCat.js │ └── useToggle.js ├── episode-13 ├── 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 │ ├── Fact.js │ ├── Form.js │ ├── factAction.js │ ├── factReducer.js │ ├── formReducer.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ ├── setupTests.js │ ├── useCount.js │ ├── useGetCat.js │ └── useToggle.js ├── episode-14 ├── 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 │ ├── Contact.js │ ├── Home.js │ ├── Login.js │ ├── Store.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-15 ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.css │ ├── App.tsx │ ├── Person.tsx │ ├── index.tsx │ └── react-app-env.d.ts └── tsconfig.json ├── episode-2 ├── 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 │ ├── Person.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-3 ├── 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 │ ├── User.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-4 ├── 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 │ ├── User.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-5 ├── 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 │ ├── Course.js │ ├── User.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-6 ├── 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 │ ├── Text.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-7 ├── .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 │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-8 ├── .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 │ ├── Pages │ ├── About.js │ ├── Contact.js │ ├── Home.js │ ├── Nav.js │ └── Profile.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── episode-9 ├── 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 │ ├── Components │ └── ChangeProfile.js │ ├── Pages │ ├── Contact.js │ ├── Home.js │ ├── Nav.js │ └── Profile.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ └── setupTests.js ├── online-shop ├── 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 │ ├── assets │ ├── bag.jpg │ ├── camera.png │ ├── denim.jpg │ ├── high-heel.jpg │ ├── laptop.jpg │ ├── mobile.jpg │ ├── shoes.jpg │ └── sunglass.webp │ ├── components │ ├── nav.css │ ├── nav.js │ └── welcome.js │ ├── context │ ├── shopContext-context.js │ └── shopContext.js │ ├── data │ └── products.js │ ├── hook │ └── useCart.js │ ├── index.js │ └── pages │ ├── cart │ └── cart.jsx │ └── shop │ ├── product.js │ └── shop.jsx ├── package-lock.json └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 sarvin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Reactjs 2 | Reactjs tutorial 3 | -------------------------------------------------------------------------------- /episode-10/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 | -------------------------------------------------------------------------------- /episode-10/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@tanstack/react-query": "^4.29.5", 7 | "@testing-library/jest-dom": "^5.16.5", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "axios": "^1.3.5", 11 | "react": "^18.2.0", 12 | "react-dom": "^18.2.0", 13 | "react-query": "^3.39.3", 14 | "react-router-dom": "^6.10.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 | } 43 | -------------------------------------------------------------------------------- /episode-10/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-10/public/favicon.ico -------------------------------------------------------------------------------- /episode-10/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-10/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-10/public/logo192.png -------------------------------------------------------------------------------- /episode-10/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-10/public/logo512.png -------------------------------------------------------------------------------- /episode-10/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 | -------------------------------------------------------------------------------- /episode-10/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-10/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-10/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import {BrowserRouter as Router , Routes , Route } from "react-router-dom" 3 | import {Home} from "./Pages/Home" 4 | import { Contact } from "./Pages/Contact"; 5 | import { Nav } from "./Pages/Nav"; 6 | import {Profile} from "./Pages/Profile" 7 | import {QueryClient , QueryClientProvider} from 'react-query' 8 | function App() { 9 | const client = new QueryClient({ defaultOptions :{ 10 | queries : { refetchOnWindowFocus : false} 11 | }}) 12 | return
13 | 14 | 15 |
} /> 21 | 22 | 23 | 24 | ; 25 | } 26 | export default App; 27 | -------------------------------------------------------------------------------- /episode-10/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 | -------------------------------------------------------------------------------- /episode-10/src/Pages/Contact.js: -------------------------------------------------------------------------------- 1 | export const Contact=() =>{ 2 | return
This is Contact page
3 | } -------------------------------------------------------------------------------- /episode-10/src/Pages/Home.js: -------------------------------------------------------------------------------- 1 | import { useQuery } from "react-query"; 2 | import Axios from "axios"; 3 | export const Home = () => { 4 | const { data : catData, isLoading , isError , error , refetch } = useQuery(["cat"], () => { 5 | return Axios.get("https://catfact.ninja/fact").then((res) => res.data); 6 | }); 7 | 8 | if (isLoading) return

Loading ...

; 9 | if(isError) return

sorry , there was an error : error : {error.message}

10 | return ( 11 |
12 | home page 13 |

{catData?.fact}

14 | 15 |
16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /episode-10/src/Pages/Nav.js: -------------------------------------------------------------------------------- 1 | import {Link} from "react-router-dom" 2 | export const Nav=()=>{ 3 | return( ) 8 | } -------------------------------------------------------------------------------- /episode-10/src/Pages/Profile.js: -------------------------------------------------------------------------------- 1 | export const Profile=() =>{ 2 | 3 | return
Profile Page 4 |
5 | } -------------------------------------------------------------------------------- /episode-10/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 | -------------------------------------------------------------------------------- /episode-10/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-10/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-10/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 | -------------------------------------------------------------------------------- /episode-10/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 | -------------------------------------------------------------------------------- /episode-11/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 | -------------------------------------------------------------------------------- /episode-11/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@hookform/resolvers": "^3.1.0", 7 | "@tanstack/react-query": "^4.29.5", 8 | "@testing-library/jest-dom": "^5.16.5", 9 | "@testing-library/react": "^13.4.0", 10 | "@testing-library/user-event": "^13.5.0", 11 | "axios": "^1.3.5", 12 | "react": "^18.2.0", 13 | "react-dom": "^18.2.0", 14 | "react-hook-form": "^7.43.9", 15 | "react-query": "^3.39.3", 16 | "react-router-dom": "^6.10.0", 17 | "react-scripts": "5.0.1", 18 | "web-vitals": "^2.1.4", 19 | "yup": "^1.1.1" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /episode-11/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-11/public/favicon.ico -------------------------------------------------------------------------------- /episode-11/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-11/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-11/public/logo192.png -------------------------------------------------------------------------------- /episode-11/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-11/public/logo512.png -------------------------------------------------------------------------------- /episode-11/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 | -------------------------------------------------------------------------------- /episode-11/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-11/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | width: 250px; 3 | text-align: center; 4 | margin: auto; 5 | } 6 | input{display: block; width: 100%;} 7 | .success { 8 | background-color: green; 9 | } 10 | .warnning { 11 | background-color: red; 12 | } 13 | .App-logo { 14 | height: 40vmin; 15 | pointer-events: none; 16 | } 17 | 18 | @media (prefers-reduced-motion: no-preference) { 19 | .App-logo { 20 | animation: App-logo-spin infinite 20s linear; 21 | } 22 | } 23 | 24 | .App-header { 25 | background-color: #282c34; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | align-items: center; 30 | justify-content: center; 31 | font-size: calc(10px + 2vmin); 32 | color: white; 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | } 38 | 39 | @keyframes App-logo-spin { 40 | from { 41 | transform: rotate(0deg); 42 | } 43 | to { 44 | transform: rotate(360deg); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /episode-11/src/App.js: -------------------------------------------------------------------------------- 1 | 2 | import "./App.css"; 3 | import SubmitForm from "./Components/submitForm"; 4 | function App() { 5 | return
6 | 7 |
; 8 | } 9 | export default App; 10 | -------------------------------------------------------------------------------- /episode-11/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 | -------------------------------------------------------------------------------- /episode-11/src/Components/submitForm.js: -------------------------------------------------------------------------------- 1 | import {useForm} from 'react-hook-form' 2 | import * as yup from 'yup' 3 | import {yupResolver} from '@hookform/resolvers/yup' 4 | 5 | const SubmitForm = () => { 6 | const schema = yup.object().shape({ 7 | name : yup.string().required("فیلد نام اجباری است"), 8 | email : yup.string().email("ایمیل نا معتبر هست").required("ایمیل اجباری است"), 9 | age : yup.number().positive().min(18).max(100).required(), 10 | password : yup.string().min(4).max(15).required(), 11 | confirmPassword : yup.string().oneOf([yup.ref("password")] , "password not matches").required() 12 | }) 13 | 14 | const {register , handleSubmit , formState:{errors}} = 15 | useForm({resolver : yupResolver(schema)}) 16 | 17 | const onFormSubmit = (data)=>{ 18 | console.log("the form is submited") 19 | console.log(data) 20 | } 21 | return ( 22 |
23 | 24 | { errors.name && ( 25 |

{errors.name?.message}

26 | )} 27 | 28 |

{errors.email?.message}

29 | 30 |

{errors.age?.message}

31 | 32 |

{errors.password?.message}

33 | 34 |

{errors.confirmPassword?.message}

35 | 36 |
37 | ); 38 | }; 39 | export default SubmitForm; 40 | -------------------------------------------------------------------------------- /episode-11/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 | -------------------------------------------------------------------------------- /episode-11/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-11/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-11/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 | -------------------------------------------------------------------------------- /episode-11/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 | -------------------------------------------------------------------------------- /episode-12/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@hookform/resolvers": "^3.1.0", 7 | "@tanstack/react-query": "^4.29.5", 8 | "@testing-library/jest-dom": "^5.16.5", 9 | "@testing-library/react": "^13.4.0", 10 | "@testing-library/user-event": "^13.5.0", 11 | "axios": "^1.3.5", 12 | "react": "^18.2.0", 13 | "react-dom": "^18.2.0", 14 | "react-hook-form": "^7.43.9", 15 | "react-query": "^3.39.3", 16 | "react-router-dom": "^6.10.0", 17 | "react-scripts": "5.0.1", 18 | "web-vitals": "^2.1.4", 19 | "yup": "^1.1.1" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /episode-12/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-12/public/favicon.ico -------------------------------------------------------------------------------- /episode-12/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-12/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-12/public/logo192.png -------------------------------------------------------------------------------- /episode-12/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-12/public/logo512.png -------------------------------------------------------------------------------- /episode-12/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 | -------------------------------------------------------------------------------- /episode-12/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-12/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | width: 250px; 3 | text-align: center; 4 | margin: auto; 5 | } 6 | input{display: block; width: 100%;} 7 | .success { 8 | background-color: green; 9 | } 10 | .warnning { 11 | background-color: red; 12 | } 13 | .App-logo { 14 | height: 40vmin; 15 | pointer-events: none; 16 | } 17 | 18 | @media (prefers-reduced-motion: no-preference) { 19 | .App-logo { 20 | animation: App-logo-spin infinite 20s linear; 21 | } 22 | } 23 | 24 | .App-header { 25 | background-color: #282c34; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | align-items: center; 30 | justify-content: center; 31 | font-size: calc(10px + 2vmin); 32 | color: white; 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | } 38 | 39 | @keyframes App-logo-spin { 40 | from { 41 | transform: rotate(0deg); 42 | } 43 | to { 44 | transform: rotate(360deg); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /episode-12/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { useCount } from "./useCount"; 3 | function App() { 4 | const {count , increase , decrease , reset} = useCount(20); 5 | 6 | return(
7 | {count} 8 | 9 | 10 | 11 |
); 12 | } 13 | export default App; -------------------------------------------------------------------------------- /episode-12/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 | -------------------------------------------------------------------------------- /episode-12/src/Cat.js: -------------------------------------------------------------------------------- 1 | import { useGetCat } from "./useGetCat"; 2 | 3 | export const Cat = () => { 4 | const {data :catData , isLoading , refechData} = useGetCat(); 5 | 6 | if(isLoading) return

Loading...

7 | return ( 8 |
9 | 10 |

{catData?.fact}

11 |
12 | ); 13 | }; 14 | -------------------------------------------------------------------------------- /episode-12/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 | -------------------------------------------------------------------------------- /episode-12/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-12/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-12/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 | -------------------------------------------------------------------------------- /episode-12/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 | -------------------------------------------------------------------------------- /episode-12/src/useCount.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | 3 | export const useCount=(intialValue = 0)=>{ 4 | const [ count ,setCount] = useState(intialValue) 5 | const increase =()=>{ 6 | setCount((prev)=> prev+1) 7 | } 8 | const decrease =()=>{ 9 | setCount((prev)=> prev-1) 10 | } 11 | const reset =()=>{ 12 | setCount(0) 13 | } 14 | return {count , increase , decrease , reset} 15 | } -------------------------------------------------------------------------------- /episode-12/src/useGetCat.js: -------------------------------------------------------------------------------- 1 | import { useQuery } from "@tanstack/react-query"; 2 | import Axios from "axios"; 3 | 4 | export const useGetCat =() =>{ 5 | const { data , isLoading , refetch , error} = useQuery(["cat"], async () => { 6 | return Axios.get("https://catfact.ninja/fact") 7 | .then((res) => res.data); 8 | 9 | }); 10 | 11 | const refechData =()=>{ 12 | alert("data refetched"); 13 | refetch() 14 | } 15 | return {data , isLoading ,refechData , error} 16 | } -------------------------------------------------------------------------------- /episode-12/src/useToggle.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | 3 | export const useToggle=(intialValue = false)=>{ 4 | const [state , setState] = useState(intialValue) 5 | 6 | const toggle=()=>{ 7 | setState((prev)=> !prev) 8 | } 9 | 10 | return {state , toggle} 11 | } -------------------------------------------------------------------------------- /episode-13/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@hookform/resolvers": "^3.1.0", 7 | "@tanstack/react-query": "^4.29.5", 8 | "@testing-library/jest-dom": "^5.16.5", 9 | "@testing-library/react": "^13.4.0", 10 | "@testing-library/user-event": "^13.5.0", 11 | "axios": "^1.3.5", 12 | "react": "^18.2.0", 13 | "react-dom": "^18.2.0", 14 | "react-hook-form": "^7.43.9", 15 | "react-query": "^3.39.3", 16 | "react-router-dom": "^6.10.0", 17 | "react-scripts": "5.0.1", 18 | "web-vitals": "^2.1.4", 19 | "yup": "^1.1.1" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /episode-13/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-13/public/favicon.ico -------------------------------------------------------------------------------- /episode-13/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-13/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-13/public/logo192.png -------------------------------------------------------------------------------- /episode-13/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-13/public/logo512.png -------------------------------------------------------------------------------- /episode-13/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 | -------------------------------------------------------------------------------- /episode-13/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-13/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | width: 250px; 3 | text-align: center; 4 | margin: auto; 5 | } 6 | input{display: block; width: 100%;} 7 | .success { 8 | background-color: green; 9 | } 10 | .warnning { 11 | background-color: red; 12 | } 13 | .App-logo { 14 | height: 40vmin; 15 | pointer-events: none; 16 | } 17 | 18 | @media (prefers-reduced-motion: no-preference) { 19 | .App-logo { 20 | animation: App-logo-spin infinite 20s linear; 21 | } 22 | } 23 | 24 | .App-header { 25 | background-color: #282c34; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | align-items: center; 30 | justify-content: center; 31 | font-size: calc(10px + 2vmin); 32 | color: white; 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | } 38 | 39 | @keyframes App-logo-spin { 40 | from { 41 | transform: rotate(0deg); 42 | } 43 | to { 44 | transform: rotate(360deg); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /episode-13/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { Form } from "./Form"; 3 | function App() { 4 | 5 | return(
6 |
7 |
); 8 | } 9 | export default App; -------------------------------------------------------------------------------- /episode-13/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 | -------------------------------------------------------------------------------- /episode-13/src/Fact.js: -------------------------------------------------------------------------------- 1 | import Axios from "axios" 2 | import { useReducer, useState } from "react" 3 | import { factReducer, initialState } from "./factReducer" 4 | import { ACTION_TYPES } from "./factAction" 5 | 6 | export const Fact=()=>{ 7 | // const [loading, setLoading] =useState(false) 8 | // const [fact, setFact] =useState("") 9 | // const [error, setError] =useState(false) 10 | 11 | // Fetch_start : loading :true 12 | // fetch_success : loading: false 13 | // : fact : res.data.fact 14 | // 15 | // fetch_error : loading: false 16 | // : error : true 17 | 18 | const [state , dispatch] = useReducer(factReducer , initialState) 19 | 20 | const handelFetch =() => { 21 | dispatch({type : ACTION_TYPES.Fetch_start}) 22 | Axios.get("https://catfact.ninja/fact") 23 | .then((res)=>{ 24 | dispatch({type : ACTION_TYPES.fetch_success , data: res.data.fact }) 25 | console.log(res) 26 | }) 27 | .catch((error)=>{ 28 | dispatch({type: ACTION_TYPES.fetch_error}) 29 | console.log(error) 30 | }) 31 | } 32 | return( 33 |
34 | 36 | {state.error && (

Error, some thing is wrong

)} 37 | 38 |

{state.fact}

39 |
40 | ) 41 | } 42 | -------------------------------------------------------------------------------- /episode-13/src/Form.js: -------------------------------------------------------------------------------- 1 | import { useReducer, useRef, useState } from "react"; 2 | import { formReducer, initialState } from "./formReducer"; 3 | 4 | export const Form = () => { 5 | // const [product, setProduct] = useState({ 6 | // title: "", 7 | // description: "", 8 | // price: 0, 9 | // category: "", 10 | // tags: [], 11 | // quantity: 0, 12 | // }); 13 | const tagRef = useRef(); 14 | const [state, dispatch] = useReducer(formReducer, initialState); 15 | 16 | const handelInputChange = (event) => { 17 | dispatch({ 18 | type: "change_input", 19 | data: { name: event.target.name, value: event.target.value }, 20 | }); 21 | }; 22 | 23 | const handelTags = () => { 24 | const tags = tagRef.current.value.split(","); 25 | console.log(tags , tagRef.current.value) 26 | tags.forEach((t) => { 27 | dispatch({ type: "add_tag", data: t }); 28 | }); 29 | }; 30 | 31 | console.log(state); 32 | return ( 33 |
34 | 35 | 41 | 47 | 53 |

مجموعه

54 | 59 |

تگ

60 | 61 |
62 | 63 |
64 | {state.tags.map((tag) => { 65 | return ; 67 | })} 68 |
69 | 72 | تعداد {state.quantity} 73 | 76 |
77 | 78 |
79 | ); 80 | }; 81 | -------------------------------------------------------------------------------- /episode-13/src/factAction.js: -------------------------------------------------------------------------------- 1 | export const ACTION_TYPES= { 2 | Fetch_start : "Fetch_start", 3 | fetch_success : "fetch_success", 4 | fetch_error :"fetch_error" 5 | } -------------------------------------------------------------------------------- /episode-13/src/factReducer.js: -------------------------------------------------------------------------------- 1 | import { ACTION_TYPES } from "./factAction"; 2 | 3 | export const initialState = { 4 | loading: false, 5 | fact: "", 6 | error: false, 7 | }; 8 | // Fetch_start : loading :true 9 | // fetch_success : loading: false 10 | // : fact : res.data.fact 11 | // 12 | // fetch_error : loading: false 13 | // : error : true 14 | 15 | export const factReducer = (state, action) => { 16 | //{ type : , data } 17 | switch (action.type) { 18 | case ACTION_TYPES.Fetch_start: 19 | return { loading: true, fact: "", error: false }; 20 | case ACTION_TYPES.fetch_success: 21 | return { loading: false, fact: action.data, error: false }; 22 | case ACTION_TYPES.fetch_error: 23 | return { loading: false, fact: "", error: true }; 24 | default: 25 | return state; 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /episode-13/src/formReducer.js: -------------------------------------------------------------------------------- 1 | export const initialState = { 2 | title: "", 3 | description: "", 4 | price: 0, 5 | category: "", 6 | tags: [], 7 | quantity: 0, 8 | } 9 | 10 | export const formReducer =(state , action) =>{ 11 | switch (action.type){ 12 | case "change_input": 13 | return {...state , [action.data.name] : action.data.value} 14 | case "add_tag" : 15 | return {...state , tags : [...state.tags , action.data]} 16 | case "remove_tag": 17 | return {...state , tags : state.tags.filter((tag)=> tag !== action.data) } 18 | case "increase": 19 | return {...state , quantity : state.quantity + 1 } 20 | case "decrease": 21 | return {...state , quantity : state.quantity - 1 } 22 | default : return state 23 | } 24 | } -------------------------------------------------------------------------------- /episode-13/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 | -------------------------------------------------------------------------------- /episode-13/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-13/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-13/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 | -------------------------------------------------------------------------------- /episode-13/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 | -------------------------------------------------------------------------------- /episode-13/src/useCount.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | 3 | export const useCount=(intialValue = 0)=>{ 4 | const [ count ,setCount] = useState(intialValue) 5 | const increase =()=>{ 6 | setCount((prev)=> prev+1) 7 | } 8 | const decrease =()=>{ 9 | setCount((prev)=> prev-1) 10 | } 11 | const reset =()=>{ 12 | setCount(0) 13 | } 14 | return {count , increase , decrease , reset} 15 | } -------------------------------------------------------------------------------- /episode-13/src/useGetCat.js: -------------------------------------------------------------------------------- 1 | import { useQuery } from "@tanstack/react-query"; 2 | import Axios from "axios"; 3 | 4 | export const useGetCat =() =>{ 5 | const { data , isLoading , refetch , error} = useQuery(["cat"], async () => { 6 | return Axios.get("https://catfact.ninja/fact") 7 | .then((res) => res.data); 8 | 9 | }); 10 | 11 | const refechData =()=>{ 12 | alert("data refetched"); 13 | refetch() 14 | } 15 | return {data , isLoading ,refechData , error} 16 | } -------------------------------------------------------------------------------- /episode-13/src/useToggle.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | 3 | export const useToggle=(intialValue = false)=>{ 4 | const [state , setState] = useState(intialValue) 5 | 6 | const toggle=()=>{ 7 | setState((prev)=> !prev) 8 | } 9 | 10 | return {state , toggle} 11 | } -------------------------------------------------------------------------------- /episode-14/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@hookform/resolvers": "^3.1.0", 7 | "@reduxjs/toolkit": "^1.9.5", 8 | "@tanstack/react-query": "^4.29.5", 9 | "@testing-library/jest-dom": "^5.16.5", 10 | "@testing-library/react": "^13.4.0", 11 | "@testing-library/user-event": "^13.5.0", 12 | "axios": "^1.3.5", 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0", 15 | "react-hook-form": "^7.43.9", 16 | "react-query": "^3.39.3", 17 | "react-redux": "^8.0.5", 18 | "react-router-dom": "^6.10.0", 19 | "react-scripts": "5.0.1", 20 | "web-vitals": "^2.1.4", 21 | "yup": "^1.1.1" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /episode-14/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-14/public/favicon.ico -------------------------------------------------------------------------------- /episode-14/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-14/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-14/public/logo192.png -------------------------------------------------------------------------------- /episode-14/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-14/public/logo512.png -------------------------------------------------------------------------------- /episode-14/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 | -------------------------------------------------------------------------------- /episode-14/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-14/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | width: 250px; 3 | text-align: center; 4 | margin: auto; 5 | } 6 | input{display: block; width: 100%;} 7 | .success { 8 | background-color: green; 9 | } 10 | .warnning { 11 | background-color: red; 12 | } 13 | .App-logo { 14 | height: 40vmin; 15 | pointer-events: none; 16 | } 17 | 18 | @media (prefers-reduced-motion: no-preference) { 19 | .App-logo { 20 | animation: App-logo-spin infinite 20s linear; 21 | } 22 | } 23 | 24 | .App-header { 25 | background-color: #282c34; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | align-items: center; 30 | justify-content: center; 31 | font-size: calc(10px + 2vmin); 32 | color: white; 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | } 38 | 39 | @keyframes App-logo-spin { 40 | from { 41 | transform: rotate(0deg); 42 | } 43 | to { 44 | transform: rotate(360deg); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /episode-14/src/App.js: -------------------------------------------------------------------------------- 1 | import { Link, Route, BrowserRouter as Router, Routes } from "react-router-dom"; 2 | import "./App.css"; 3 | import { Home } from "./Home"; 4 | import { Login } from "./Login"; 5 | import { Contact } from "./Contact"; 6 | import {Provider} from 'react-redux' 7 | import { store } from "./Store"; 8 | function App() { 9 | //redux 10 | return(
11 | 12 | 13 | home | 14 | login | 15 | contact 16 | 17 | } /> 18 | } /> 19 | } /> 20 | 21 | 22 | 23 |
); 24 | } 25 | export default App; -------------------------------------------------------------------------------- /episode-14/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 | -------------------------------------------------------------------------------- /episode-14/src/Contact.js: -------------------------------------------------------------------------------- 1 | import { useSelector } from "react-redux" 2 | 3 | export const Contact =() =>{ 4 | const seletore = useSelector((state)=> state.user) 5 | return( 6 |
Contact {seletore.username}
7 | ) 8 | } -------------------------------------------------------------------------------- /episode-14/src/Home.js: -------------------------------------------------------------------------------- 1 | export const Home =() =>{ 2 | return( 3 |
Home
4 | ) 5 | } -------------------------------------------------------------------------------- /episode-14/src/Login.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react" 2 | import {login, logout} from './Store' 3 | import {useDispatch , useSelector} from 'react-redux' 4 | 5 | export const Login =() =>{ 6 | const [newUsername , setNewUsername] = useState("") 7 | const dispatch = useDispatch() 8 | const selector = useSelector((state)=> state.user) 9 | return( 10 |

Login {selector.username}

11 | setNewUsername(event.target.value)} /> 12 | 13 | 14 |
15 | ) 16 | } -------------------------------------------------------------------------------- /episode-14/src/Store.js: -------------------------------------------------------------------------------- 1 | import {configureStore , createSlice} from '@reduxjs/toolkit' 2 | 3 | const userSlice = createSlice({ 4 | name : "user", 5 | initialState : {username : ""}, 6 | reducers : { 7 | login : (state, action)=>{ // {username : "sarvin"} 8 | state.username = action.payload.username 9 | }, 10 | logout : (state) =>{ 11 | state.username ="" 12 | } 13 | 14 | } 15 | }) 16 | export const {login , logout} = userSlice.actions 17 | export const store = configureStore({reducer :{ 18 | user : userSlice.reducer 19 | } 20 | }) -------------------------------------------------------------------------------- /episode-14/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 | -------------------------------------------------------------------------------- /episode-14/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-14/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-14/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 | -------------------------------------------------------------------------------- /episode-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 | -------------------------------------------------------------------------------- /episode-15/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 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 | ### `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 | -------------------------------------------------------------------------------- /episode-15/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "15", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "@types/jest": "^27.5.2", 10 | "@types/node": "^16.18.34", 11 | "@types/react": "^18.2.8", 12 | "@types/react-dom": "^18.2.4", 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0", 15 | "react-scripts": "5.0.1", 16 | "typescript": "^4.9.5", 17 | "web-vitals": "^2.1.4" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-15/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-15/public/favicon.ico -------------------------------------------------------------------------------- /episode-15/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-15/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-15/public/logo192.png -------------------------------------------------------------------------------- /episode-15/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-15/public/logo512.png -------------------------------------------------------------------------------- /episode-15/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 | -------------------------------------------------------------------------------- /episode-15/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-15/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-15/src/App.tsx: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import { Person , Country} from './Person'; 3 | 4 | function App() { 5 | 6 | 7 | const getAge = (name : string) : number =>{ 8 | return 43 9 | } 10 | 11 | const age :number = getAge("sarvin") 12 | 13 | return ( 14 |
15 | 22 |
23 | ); 24 | } 25 | 26 | export default App; 27 | -------------------------------------------------------------------------------- /episode-15/src/Person.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | interface Props { 4 | name : string; 5 | email : string; 6 | age : number; 7 | isMarried? : boolean; 8 | courses : string[]; 9 | country :Country; 10 | } 11 | 12 | export enum Country { 13 | Iran = "Iran", 14 | Afghanistan = "Afghanistan", 15 | Turkmenistan ="Turkmenistan" 16 | } 17 | 18 | export const Person =(props : Props)=>{ 19 | const [name , setName] = useState("sarvin") 20 | 21 | setName("mina") 22 | 23 | return( 24 |
25 |

Name : {props.name}

26 |

Email : {props.email}

27 |

Age : {props.age}

28 |

Married : {props.isMarried ? "yes" : "No" }

29 | {props.courses.map((course : String)=>( 30 |

{course}

31 | ))} 32 |

{props.country}

33 | 34 |
35 | ) 36 | 37 | } -------------------------------------------------------------------------------- /episode-15/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import App from './App'; 4 | 5 | const root = ReactDOM.createRoot( 6 | document.getElementById('root') as HTMLElement 7 | ); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-15/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /episode-15/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /episode-2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-scripts": "5.0.1", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-2/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-2/public/favicon.ico -------------------------------------------------------------------------------- /episode-2/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-2/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-2/public/logo192.png -------------------------------------------------------------------------------- /episode-2/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-2/public/logo512.png -------------------------------------------------------------------------------- /episode-2/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 | -------------------------------------------------------------------------------- /episode-2/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-2/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-2/src/App.js: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | 3 | function App() { 4 | return ( 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | ) 16 | } 17 | 18 | const GetName = (name) => { 19 | return name 20 | } 21 | // //props 22 | // const props = { 23 | // name : "sarvin", 24 | // age : 43, 25 | // email : "salam@sarvinstyle.ir" 26 | // } 27 | 28 | const Job =(props) =>{ 29 | return
30 | {props.salary} , {props.position} , {props.company} 31 |
32 | } 33 | 34 | 35 | 36 | //Componnet 37 | const User = (props)=>{ 38 | return ( 39 |
40 |

{props.name}

41 |

{props.age}

42 |

{props.email}

43 |
44 | ) 45 | } 46 | export default App; 47 | -------------------------------------------------------------------------------- /episode-2/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 | -------------------------------------------------------------------------------- /episode-2/src/Person.js: -------------------------------------------------------------------------------- 1 | export const Person = (props)=>{ 2 | return( 3 |
4 |

Name : {props.name}

5 |

Email : {props.email}

6 |

Age : {props.age}

7 |

Married : {props.isMarreid ? "yes" : "No" }

8 | {props.courses.map((course)=>( 9 |

{course}

10 | ))} 11 |
12 | ) 13 | } -------------------------------------------------------------------------------- /episode-2/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 | -------------------------------------------------------------------------------- /episode-2/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-2/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-2/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 | -------------------------------------------------------------------------------- /episode-2/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 | -------------------------------------------------------------------------------- /episode-3/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-scripts": "5.0.1", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-3/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-3/public/favicon.ico -------------------------------------------------------------------------------- /episode-3/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-3/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-3/public/logo192.png -------------------------------------------------------------------------------- /episode-3/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-3/public/logo512.png -------------------------------------------------------------------------------- /episode-3/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 | -------------------------------------------------------------------------------- /episode-3/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-3/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-3/src/App.js: -------------------------------------------------------------------------------- 1 | import { User } from "./User"; 2 | import "./App.css"; 3 | 4 | function App() { 5 | const classes = [ 6 | { name : "html" , finished : true}, 7 | { name : "javascript" , finished : false}, 8 | { name : "css" , finished : true}, 9 | { name : "bootstrap" , finished : false}, 10 | { name : "react" , finished : true}, 11 | { name : "python" , finished : false}, 12 | ]; 13 | 14 | return ( 15 |
16 | {classes.map((c , index)=>{ 17 | return c.finished &&

{c.name}

18 | })} 19 |
20 | ) 21 | } 22 | export default App; 23 | 24 | 25 | -------------------------------------------------------------------------------- /episode-3/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 | -------------------------------------------------------------------------------- /episode-3/src/User.js: -------------------------------------------------------------------------------- 1 | export const User = (props)=>{ 2 | return (

{props.name} : {props.age}

) 3 | } 4 | //export default User; -------------------------------------------------------------------------------- /episode-3/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 | -------------------------------------------------------------------------------- /episode-3/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-3/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-3/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 | -------------------------------------------------------------------------------- /episode-3/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 | -------------------------------------------------------------------------------- /episode-4/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-scripts": "5.0.1", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-4/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-4/public/favicon.ico -------------------------------------------------------------------------------- /episode-4/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-4/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-4/public/logo192.png -------------------------------------------------------------------------------- /episode-4/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-4/public/logo512.png -------------------------------------------------------------------------------- /episode-4/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 | -------------------------------------------------------------------------------- /episode-4/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-4/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-4/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { useState } from "react"; 3 | 4 | function App() { 5 | const [count, setCount] = useState(0); 6 | const increase = () => { 7 | setCount(count + 1); 8 | }; 9 | const decrease = () => { 10 | setCount(count - 1); 11 | }; 12 | const setZero = () => { 13 | setCount(0); 14 | }; 15 | return ( 16 |
17 | 18 | 19 | 20 |

{count}

21 |
22 | ); 23 | } 24 | export default App; 25 | -------------------------------------------------------------------------------- /episode-4/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 | -------------------------------------------------------------------------------- /episode-4/src/User.js: -------------------------------------------------------------------------------- 1 | export const User = (props)=>{ 2 | return (

{props.name} : {props.age}

) 3 | } 4 | //export default User; -------------------------------------------------------------------------------- /episode-4/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 | -------------------------------------------------------------------------------- /episode-4/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-4/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-4/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 | -------------------------------------------------------------------------------- /episode-4/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 | -------------------------------------------------------------------------------- /episode-5/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-scripts": "5.0.1", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-5/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-5/public/favicon.ico -------------------------------------------------------------------------------- /episode-5/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-5/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-5/public/logo192.png -------------------------------------------------------------------------------- /episode-5/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-5/public/logo512.png -------------------------------------------------------------------------------- /episode-5/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 | -------------------------------------------------------------------------------- /episode-5/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-5/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-5/src/App.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import "./App.css"; 3 | import Course from "./Course"; 4 | 5 | function App() { 6 | const [courseList , setCourseList] = useState([]); 7 | const [newCourse, setNewCourse] = useState("") 8 | 9 | const handelChange =(event)=>{ 10 | setNewCourse(event.target.value) 11 | 12 | } 13 | 14 | const addCourse =() =>{ 15 | // let arr=[]; 16 | // const name ="sarvin" 17 | // arr.push(name) 18 | 19 | const course = { 20 | id : courseList.length === 0 ? 1 : courseList[courseList.length -1 ].id + 1 , 21 | courseName : newCourse, 22 | isCompleted : false 23 | } 24 | setCourseList( [...courseList , course]) 25 | console.log(courseList) 26 | 27 | } 28 | const deleteCourse =(courseId) =>{ 29 | setCourseList(courseList.filter((course)=> courseId !== course.id )) 30 | } 31 | 32 | const completeCourse = (courseId)=>{ 33 | const newCourseList = courseList.map((course)=>{ 34 | if (course.id === courseId) 35 | return {...course , isCompleted : !course.isCompleted} 36 | else 37 | return course 38 | }) 39 | 40 | setCourseList(newCourseList) 41 | } 42 | 43 | return ( 44 |
45 |
46 | 47 | 48 |
49 |
50 | { courseList.map ((course , index) =>{ 51 | return ( 52 | 56 | ) 57 | })} 58 | 59 |
60 |
61 | ); 62 | } 63 | export default App; 64 | -------------------------------------------------------------------------------- /episode-5/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 | -------------------------------------------------------------------------------- /episode-5/src/Course.js: -------------------------------------------------------------------------------- 1 | const Course =(props)=>{ 2 | return

{props.course.courseName}

3 | 4 | 5 |
6 | } 7 | export default Course -------------------------------------------------------------------------------- /episode-5/src/User.js: -------------------------------------------------------------------------------- 1 | export const User = (props)=>{ 2 | return (

{props.name} : {props.age}

) 3 | } 4 | //export default User; -------------------------------------------------------------------------------- /episode-5/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 | -------------------------------------------------------------------------------- /episode-5/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-5/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-5/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 | -------------------------------------------------------------------------------- /episode-5/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 | -------------------------------------------------------------------------------- /episode-6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-scripts": "5.0.1", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /episode-6/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-6/public/favicon.ico -------------------------------------------------------------------------------- /episode-6/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-6/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-6/public/logo192.png -------------------------------------------------------------------------------- /episode-6/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-6/public/logo512.png -------------------------------------------------------------------------------- /episode-6/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 | -------------------------------------------------------------------------------- /episode-6/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-6/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-6/src/App.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import "./App.css"; 3 | import Text from "./Text" 4 | 5 | // mounting 6 | // updating 7 | // unmounting 8 | 9 | function App() { 10 | const [showText, setShowText] = useState(false) 11 | return ( 12 |
13 | 14 | {showText && } 15 |
16 | ) 17 | } 18 | export default App; 19 | -------------------------------------------------------------------------------- /episode-6/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 | -------------------------------------------------------------------------------- /episode-6/src/Text.js: -------------------------------------------------------------------------------- 1 | 2 | import { useEffect, useState } from "react" 3 | 4 | const Text=() =>{ 5 | const [text,setText] = useState(""); 6 | 7 | //mounting stage 8 | useEffect(()=>{ 9 | console.log("Component did mount") 10 | 11 | return () =>{ 12 | console.log("component unmount") 13 | } 14 | }, []) 15 | 16 | // // update stage 17 | // useEffect(()=>{ 18 | // console.log("Component updated") 19 | // }, [text]) 20 | 21 | return( 22 |
23 | setText(e.target.value)} /> 24 |

{text}

25 |
26 | ) 27 | } 28 | export default Text -------------------------------------------------------------------------------- /episode-6/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 | -------------------------------------------------------------------------------- /episode-6/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /episode-6/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-6/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 | -------------------------------------------------------------------------------- /episode-6/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 | -------------------------------------------------------------------------------- /episode-7/.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 | -------------------------------------------------------------------------------- /episode-7/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^1.3.5", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-scripts": "5.0.1", 13 | "web-vitals": "^2.1.4" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /episode-7/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-7/public/favicon.ico -------------------------------------------------------------------------------- /episode-7/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-7/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-7/public/logo192.png -------------------------------------------------------------------------------- /episode-7/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-7/public/logo512.png -------------------------------------------------------------------------------- /episode-7/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 | -------------------------------------------------------------------------------- /episode-7/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-7/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-7/src/App.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import "./App.css"; 3 | import Axios from "axios"; 4 | 5 | function App() { 6 | //https://excuser-three.vercel.app/v1/excuse/party 7 | 8 | 9 | const [generateExcuse, setGenerageExcuse]=useState(""); 10 | 11 | const fetchExcuse= (excuse)=>{ 12 | Axios.get(`https://excuser-three.vercel.app/v1/excuse/${excuse}/`).then((res)=>{ 13 | setGenerageExcuse(res.data[0].excuse) 14 | }) 15 | } 16 | 17 | return ( 18 |
19 |

Generate an excuse

20 | 21 | 22 | 23 |

{generateExcuse}

24 |
25 | ); 26 | } 27 | export default App; 28 | -------------------------------------------------------------------------------- /episode-7/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 | -------------------------------------------------------------------------------- /episode-7/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 | -------------------------------------------------------------------------------- /episode-7/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | // 10 | 11 | // 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 | -------------------------------------------------------------------------------- /episode-7/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-7/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 | -------------------------------------------------------------------------------- /episode-7/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 | -------------------------------------------------------------------------------- /episode-8/.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 | -------------------------------------------------------------------------------- /episode-8/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^1.3.5", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-router-dom": "^6.10.0", 13 | "react-scripts": "5.0.1", 14 | "web-vitals": "^2.1.4" 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 | -------------------------------------------------------------------------------- /episode-8/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-8/public/favicon.ico -------------------------------------------------------------------------------- /episode-8/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-8/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-8/public/logo192.png -------------------------------------------------------------------------------- /episode-8/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-8/public/logo512.png -------------------------------------------------------------------------------- /episode-8/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 | -------------------------------------------------------------------------------- /episode-8/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-8/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-8/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import {BrowserRouter as Router , Routes , Route , Link} from "react-router-dom" 3 | import {Home} from "./Pages/Home" 4 | import { About } from "./Pages/About"; 5 | import { Contact } from "./Pages/Contact"; 6 | import { Nav } from "./Pages/Nav"; 7 | import {Profile} from "./Pages/Profile" 8 | function App() { 9 | return
10 | 11 |
SarvinStyle
12 |
} /> 19 | 20 |
This is footer
21 | 22 | 23 | ; 24 | } 25 | export default App; 26 | -------------------------------------------------------------------------------- /episode-8/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 | -------------------------------------------------------------------------------- /episode-8/src/Pages/About.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import {useNavigate} from 'react-router-dom' 3 | export const About=() =>{ 4 | let navigate = useNavigate() 5 | return ( 6 | 7 |
This is About page
8 | 9 |
) 10 | } -------------------------------------------------------------------------------- /episode-8/src/Pages/Contact.js: -------------------------------------------------------------------------------- 1 | export const Contact=() =>{ 2 | return
This is Contact page
3 | } -------------------------------------------------------------------------------- /episode-8/src/Pages/Home.js: -------------------------------------------------------------------------------- 1 | export const Home=() =>{ 2 | return
This is home page
3 | } 4 | -------------------------------------------------------------------------------- /episode-8/src/Pages/Nav.js: -------------------------------------------------------------------------------- 1 | import {Link} from "react-router-dom" 2 | export const Nav=()=>{ 3 | return( ) 8 | } -------------------------------------------------------------------------------- /episode-8/src/Pages/Profile.js: -------------------------------------------------------------------------------- 1 | import {useParams} from 'react-router-dom' 2 | 3 | export const Profile=() =>{ 4 | const {name , id} = useParams() 5 | return
This is Profile page of {name} - {id}
6 | } -------------------------------------------------------------------------------- /episode-8/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 | -------------------------------------------------------------------------------- /episode-8/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | // 10 | 11 | // 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 | -------------------------------------------------------------------------------- /episode-8/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-8/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 | -------------------------------------------------------------------------------- /episode-8/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 | -------------------------------------------------------------------------------- /episode-9/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "episode-1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^1.3.5", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-router-dom": "^6.10.0", 13 | "react-scripts": "5.0.1", 14 | "web-vitals": "^2.1.4" 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 | -------------------------------------------------------------------------------- /episode-9/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-9/public/favicon.ico -------------------------------------------------------------------------------- /episode-9/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /episode-9/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-9/public/logo192.png -------------------------------------------------------------------------------- /episode-9/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/episode-9/public/logo512.png -------------------------------------------------------------------------------- /episode-9/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 | -------------------------------------------------------------------------------- /episode-9/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /episode-9/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | .success { 5 | background-color: green; 6 | } 7 | .warnning { 8 | background-color: red; 9 | } 10 | .App-logo { 11 | height: 40vmin; 12 | pointer-events: none; 13 | } 14 | 15 | @media (prefers-reduced-motion: no-preference) { 16 | .App-logo { 17 | animation: App-logo-spin infinite 20s linear; 18 | } 19 | } 20 | 21 | .App-header { 22 | background-color: #282c34; 23 | min-height: 100vh; 24 | display: flex; 25 | flex-direction: column; 26 | align-items: center; 27 | justify-content: center; 28 | font-size: calc(10px + 2vmin); 29 | color: white; 30 | } 31 | 32 | .App-link { 33 | color: #61dafb; 34 | } 35 | 36 | @keyframes App-logo-spin { 37 | from { 38 | transform: rotate(0deg); 39 | } 40 | to { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /episode-9/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import {BrowserRouter as Router , Routes , Route } from "react-router-dom" 3 | import {Home} from "./Pages/Home" 4 | import { Contact } from "./Pages/Contact"; 5 | import { Nav } from "./Pages/Nav"; 6 | import {Profile} from "./Pages/Profile" 7 | import { useState, createContext } from "react"; 8 | 9 | export const ProfileContext = createContext(); 10 | 11 | function App() { 12 | const [username , setUsername]=useState("sarvinstyle") 13 | return
14 | 15 | 16 |
} /> 22 | 23 | 24 | 25 | ; 26 | } 27 | export default App; 28 | -------------------------------------------------------------------------------- /episode-9/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 | -------------------------------------------------------------------------------- /episode-9/src/Components/ChangeProfile.js: -------------------------------------------------------------------------------- 1 | import { useContext, useState } from "react" 2 | import { ProfileContext } from "../App" 3 | 4 | export const ChangeProfile =() =>{ 5 | const {setUsername} = useContext(ProfileContext) 6 | const [newUsername , setNewUserName] = useState("") 7 | return( 8 |
9 | { setNewUserName(event.target.value)}} /> 10 | 11 |
12 | ) 13 | } -------------------------------------------------------------------------------- /episode-9/src/Pages/Contact.js: -------------------------------------------------------------------------------- 1 | export const Contact=() =>{ 2 | return
This is Contact page
3 | } -------------------------------------------------------------------------------- /episode-9/src/Pages/Home.js: -------------------------------------------------------------------------------- 1 | import {useContext} from 'react' 2 | import { ProfileContext } from '../App' 3 | 4 | export const Home=() =>{ 5 | const {username} = useContext(ProfileContext) 6 | return
home page - username is {username}
7 | } 8 | -------------------------------------------------------------------------------- /episode-9/src/Pages/Nav.js: -------------------------------------------------------------------------------- 1 | import {Link} from "react-router-dom" 2 | export const Nav=()=>{ 3 | return( ) 8 | } -------------------------------------------------------------------------------- /episode-9/src/Pages/Profile.js: -------------------------------------------------------------------------------- 1 | import { useContext } from "react" 2 | import { ChangeProfile } from "../Components/ChangeProfile" 3 | import { ProfileContext } from "../App" 4 | 5 | export const Profile=() =>{ 6 | const {username} = useContext(ProfileContext) 7 | return
Profile Page - username is {username} 8 | 9 |
10 | } -------------------------------------------------------------------------------- /episode-9/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 | -------------------------------------------------------------------------------- /episode-9/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 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | // 10 | 11 | // 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 | -------------------------------------------------------------------------------- /episode-9/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /episode-9/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 | -------------------------------------------------------------------------------- /episode-9/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 | -------------------------------------------------------------------------------- /online-shop/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "online-shop", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@fortawesome/fontawesome-svg-core": "^6.4.0", 7 | "@fortawesome/free-solid-svg-icons": "^6.4.0", 8 | "@fortawesome/react-fontawesome": "^0.2.0", 9 | "@testing-library/jest-dom": "^5.16.5", 10 | "@testing-library/react": "^13.4.0", 11 | "@testing-library/user-event": "^13.5.0", 12 | "bootstrap": "^5.3.0", 13 | "react": "^18.2.0", 14 | "react-bootstrap": "^2.8.0", 15 | "react-dom": "^18.2.0", 16 | "react-router-dom": "^6.14.0", 17 | "react-scripts": "5.0.1", 18 | "web-vitals": "^2.1.4" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": [ 28 | "react-app", 29 | "react-app/jest" 30 | ] 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /online-shop/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/public/favicon.ico -------------------------------------------------------------------------------- /online-shop/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /online-shop/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/public/logo192.png -------------------------------------------------------------------------------- /online-shop/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/public/logo512.png -------------------------------------------------------------------------------- /online-shop/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 | -------------------------------------------------------------------------------- /online-shop/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /online-shop/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /online-shop/src/App.js: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import 'bootstrap/dist/css/bootstrap.min.css' 3 | import {BrowserRouter as Router , Route , Routes} from 'react-router-dom' 4 | import Shop from './pages/shop/shop'; 5 | import Cart from './pages/cart/cart'; 6 | import Nav from './components/nav'; 7 | import {ShopContextProvider} from './context/shopContext' 8 | import Welcome from './components/welcome'; 9 | function App() { 10 | return ( 11 |
12 | 13 | 14 |
24 | ); 25 | } 26 | 27 | export default App; 28 | -------------------------------------------------------------------------------- /online-shop/src/assets/bag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/bag.jpg -------------------------------------------------------------------------------- /online-shop/src/assets/camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/camera.png -------------------------------------------------------------------------------- /online-shop/src/assets/denim.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/denim.jpg -------------------------------------------------------------------------------- /online-shop/src/assets/high-heel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/high-heel.jpg -------------------------------------------------------------------------------- /online-shop/src/assets/laptop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/laptop.jpg -------------------------------------------------------------------------------- /online-shop/src/assets/mobile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/mobile.jpg -------------------------------------------------------------------------------- /online-shop/src/assets/shoes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/shoes.jpg -------------------------------------------------------------------------------- /online-shop/src/assets/sunglass.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarvinstyle/React.js-tutorial/08466d9a4a63b59a3a890805da44f5bc0d041e68/online-shop/src/assets/sunglass.webp -------------------------------------------------------------------------------- /online-shop/src/components/nav.css: -------------------------------------------------------------------------------- 1 | .cart-items-count { 2 | padding-left: 9px; 3 | padding-right: 9px; 4 | -webkit-border-radius: 9px; 5 | -moz-border-radius: 9px; 6 | border-radius: 9px; 7 | font-size: 12px; 8 | background: #ff0000; 9 | color: #fff; 10 | padding: 0 5px; 11 | vertical-align: top; 12 | margin-left: 0px; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /online-shop/src/components/nav.js: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; 3 | import { faShoppingCart } from "@fortawesome/free-solid-svg-icons"; 4 | import { useContext } from "react"; 5 | import { ShopContext } from "../context/shopContext"; 6 | import './nav.css' 7 | const Nav = () => { 8 | const {cartItems} = useContext(ShopContext) 9 | const itemCount = cartItems?.reduce((prev , current)=> { 10 | return prev + current.count 11 | },0) 12 | return ( 13 |
14 |
15 | SarvinStyle Codding 16 |
    17 |
  • 18 | 19 | Shop 20 | 21 |
  • 22 |
  • 23 | 24 | 25 | {itemCount > 0 && {itemCount}} 26 | 27 |
  • 28 |
29 |
30 |
31 | ); 32 | }; 33 | export default Nav; 34 | -------------------------------------------------------------------------------- /online-shop/src/components/welcome.js: -------------------------------------------------------------------------------- 1 | import { faClose } from "@fortawesome/free-solid-svg-icons"; 2 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; 3 | import React, { useEffect, useState } from "react"; 4 | 5 | const Welcome=()=>{ 6 | const [showWelcome , setShowWelcome] = useState(); 7 | useEffect(()=>{ 8 | const data = localStorage.getItem("show_app_intro") 9 | setShowWelcome(JSON.parse(data) ?? true) 10 | },[]) 11 | const onHideWelcome =()=>{ 12 | setShowWelcome(false); 13 | localStorage.setItem("show_app_intro" , JSON.stringify(false)) 14 | } 15 | return( 16 | 17 | { showWelcome && ( 18 |
19 |
20 | 25 |
welcome
26 |
27 |
28 | )} 29 |
30 | 31 | ) 32 | } 33 | export default Welcome -------------------------------------------------------------------------------- /online-shop/src/context/shopContext-context.js: -------------------------------------------------------------------------------- 1 | import { createContext , useState} from "react"; 2 | 3 | export const ShopContext = createContext(null); 4 | 5 | export const ShopContextProvider =(props)=>{ 6 | const [cartItems , setCartItems] = useState([]) 7 | 8 | const addToCart =(itemId)=>{ 9 | if( !cartItems?.find((item)=> item.id === itemId)) 10 | setCartItems([...cartItems , {id : itemId , count : 1}]) 11 | else 12 | setCartItems(cartItems.map((item)=>{ 13 | if( item.id=== itemId) 14 | return {...item , count : item.count + 1} 15 | else return item 16 | })) 17 | console.log(cartItems) 18 | } 19 | 20 | const removeFromCart =(itemId) =>{ 21 | setCartItems(cartItems.map ((i)=>{ 22 | if(i.id ===itemId) 23 | return {...i , count : i.count ===0 ? 0: i.count - 1} 24 | else return i 25 | })) 26 | } 27 | const contextValue = {cartItems,addToCart , removeFromCart } 28 | return {props.children} 29 | 30 | } 31 | -------------------------------------------------------------------------------- /online-shop/src/context/shopContext.js: -------------------------------------------------------------------------------- 1 | import { createContext } from "react"; 2 | import { useCart } from "../hook/useCart"; 3 | 4 | export const ShopContext = createContext({ 5 | cartItems: null, 6 | addToCart: () => {}, 7 | removeFromCart: () => {}, 8 | resetCart :() =>{} 9 | }); 10 | 11 | export const ShopContextProvider = (props) => { 12 | return ( 13 | 14 | {props.children} 15 | 16 | ); 17 | }; 18 | -------------------------------------------------------------------------------- /online-shop/src/data/products.js: -------------------------------------------------------------------------------- 1 | import mobile from '../assets/mobile.jpg' 2 | import laptop from '../assets/laptop.jpg' 3 | import camera from '../assets/camera.png' 4 | import denim from '../assets/denim.jpg' 5 | import shoes from '../assets/shoes.jpg' 6 | export const PRODUCTS =[ 7 | { 8 | id : 1, 9 | productName : "Mobile", 10 | price : 1000, 11 | productImage : mobile 12 | }, 13 | { 14 | id : 2, 15 | productName : "laptop", 16 | price : 1500, 17 | productImage : laptop 18 | }, 19 | { 20 | id : 3, 21 | productName : "camera", 22 | price : 1700, 23 | productImage : camera 24 | } 25 | , 26 | { 27 | id : 4, 28 | productName : "denim", 29 | price : 1700, 30 | productImage : denim 31 | } , 32 | { 33 | id : 5, 34 | productName : "shoes", 35 | price : 500, 36 | productImage : shoes 37 | } 38 | ] -------------------------------------------------------------------------------- /online-shop/src/hook/useCart.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react" 2 | 3 | export const useCart =()=>{ 4 | const [cartItems , setCartItems] = useState(); 5 | 6 | 7 | useEffect(()=>{ 8 | const data = localStorage.getItem("SarvinStyleCodding_cart") 9 | setCartItems(!!JSON.parse(data) ? JSON.parse(data) : []) 10 | } 11 | ,[]) 12 | useEffect(()=>{ 13 | if( cartItems !== undefined) 14 | localStorage.setItem("SarvinStyleCodding_cart" , JSON.stringify(cartItems)) 15 | },[cartItems]) 16 | 17 | const addToCart =(itemId)=>{ 18 | if( !cartItems?.find((item)=> item.id === itemId)) 19 | setCartItems([...cartItems , {id : itemId , count : 1}]) 20 | else 21 | setCartItems(cartItems.map((item)=>{ 22 | if( item.id=== itemId) 23 | return {...item , count : item.count + 1} 24 | else return item 25 | })) 26 | console.log(cartItems) 27 | } 28 | 29 | const removeFromCart =(itemId) =>{ 30 | setCartItems(cartItems.map ((i)=>{ 31 | if(i.id ===itemId) 32 | return {...i , count : i.count ===0 ? 0: i.count - 1} 33 | else return i 34 | })) 35 | } 36 | 37 | const resetCart =()=>{ 38 | setCartItems(); 39 | localStorage.removeItem("SarvinStyleCodding_cart") 40 | localStorage.clear() 41 | } 42 | return {cartItems , addToCart , removeFromCart,resetCart} 43 | } -------------------------------------------------------------------------------- /online-shop/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import App from './App'; 4 | 5 | const root = ReactDOM.createRoot(document.getElementById('root')); 6 | root.render( 7 | 8 | 9 | 10 | ); 11 | 12 | // If you want to start measuring performance in your app, pass a function 13 | // to log results (for example: reportWebVitals(console.log)) 14 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 15 | -------------------------------------------------------------------------------- /online-shop/src/pages/cart/cart.jsx: -------------------------------------------------------------------------------- 1 | import React, { useContext } from "react"; 2 | import { PRODUCTS } from "../../data/products"; 3 | import { ShopContext } from "../../context/shopContext"; 4 | import Product from "../shop/product"; 5 | 6 | const Cart =() => { 7 | const {cartItems , resetCart} = useContext(ShopContext) 8 | return( 9 | 10 |

Your cart items

11 |
12 | {PRODUCTS.map((p)=>{ 13 | if( cartItems?.some((i)=> i.id===p.id && i.count >0)) 14 | return 15 | })} 16 |
17 | 18 |
19 | ) 20 | } 21 | export default Cart; -------------------------------------------------------------------------------- /online-shop/src/pages/shop/product.js: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | import { ShopContext } from "../../context/shopContext"; 3 | 4 | const Product = (props) => { 5 | const { id, productName, productImage, price } = props.data; 6 | const { cartItems, addToCart, removeFromCart } = useContext(ShopContext); 7 | 8 | const isInCart = cartItems?.some((item) => item.id === id); 9 | return ( 10 |
11 | 12 |
{productName}
13 |

price : {price}$

14 | 17 | 18 | {cartItems?.filter((row) => row.id === id)[0]?.count} 19 | 20 | {isInCart && ( 21 | 27 | )} 28 |
29 | ); 30 | }; 31 | export default Product; 32 | -------------------------------------------------------------------------------- /online-shop/src/pages/shop/shop.jsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Product from "./product"; 3 | import { PRODUCTS } from "../../data/products"; 4 | const Shop = () => { 5 | return ( 6 | 7 |

Shop

8 |
9 | {PRODUCTS.map((productData) => ( 10 | 11 | ))} 12 |
13 |
14 | ); 15 | }; 16 | export default Shop; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "online-shop", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@fortawesome/fontawesome-svg-core": "^6.4.0", 7 | "@fortawesome/free-solid-svg-icons": "^6.4.0", 8 | "@fortawesome/react-fontawesome": "^0.2.0", 9 | "@testing-library/jest-dom": "^5.16.5", 10 | "@testing-library/react": "^13.4.0", 11 | "@testing-library/user-event": "^13.5.0", 12 | "bootstrap": "^5.3.0", 13 | "react": "^18.2.0", 14 | "react-bootstrap": "^2.8.0", 15 | "react-dom": "^18.2.0", 16 | "react-router-dom": "^6.14.0", 17 | "react-scripts": "5.0.1", 18 | "web-vitals": "^2.1.4" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": [ 28 | "react-app", 29 | "react-app/jest" 30 | ] 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | } 44 | } 45 | --------------------------------------------------------------------------------