├── .gitattributes ├── README.md ├── client ├── .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 │ ├── components │ ├── Article.js │ ├── Comments.css │ ├── Comments.js │ ├── ErrorBoundary.js │ ├── SingleComment.css │ ├── SingleComment.js │ ├── logo.png │ └── timeFunc.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── serviceWorker.js │ └── setupTests.js ├── readme-files └── NqmT96pg4U.gif └── server ├── .gitignore ├── app.js ├── index.js ├── package-lock.json └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This is my Blog Post app! 2 | The app shows how to use refs in react with hooks. 3 | 4 | Refs are probably the most misunderstood and misused part of React. All too often, I 5 | see developers using refs to manipulate the DOM directly or work around React in 6 | someway which makes working with React much harder. In this article I am going to go 7 | over everything you need to know about refs in order to help you never make those 8 | ref mistakes. 9 | 10 | In order to work with refs in React you need to first initialize a ref which is what 11 | the useRef hook is for. This hook is very straightforward, and takes an initial 12 | value as the only argument. 13 | 14 | app link: https://blog-post-ppage.vercel.app/ 15 | 16 | 17 | my gif: 18 | ![hide](./readme-files/NqmT96pg4U.gif) -------------------------------------------------------------------------------- /client/.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 | -------------------------------------------------------------------------------- /client/README.md: -------------------------------------------------------------------------------- 1 | Create blog post page. -------------------------------------------------------------------------------- /client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.5.0", 8 | "@testing-library/user-event": "^7.2.1", 9 | "react": "^16.14.0", 10 | "react-dom": "^16.14.0", 11 | "react-scripts": "3.4.3" 12 | }, 13 | "scripts": { 14 | "start": "react-scripts start", 15 | "build": "react-scripts build", 16 | "test": "react-scripts test", 17 | "eject": "react-scripts eject" 18 | }, 19 | "eslintConfig": { 20 | "extends": "react-app" 21 | }, 22 | "browserslist": { 23 | "production": [ 24 | ">0.2%", 25 | "not dead", 26 | "not op_mini all" 27 | ], 28 | "development": [ 29 | "last 1 chrome version", 30 | "last 1 firefox version", 31 | "last 1 safari version" 32 | ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /client/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/david35008/Blog-Post-Ppage/957e1e13541be27b990926ac19a1faa220659885/client/public/favicon.ico -------------------------------------------------------------------------------- /client/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 | -------------------------------------------------------------------------------- /client/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/david35008/Blog-Post-Ppage/957e1e13541be27b990926ac19a1faa220659885/client/public/logo192.png -------------------------------------------------------------------------------- /client/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/david35008/Blog-Post-Ppage/957e1e13541be27b990926ac19a1faa220659885/client/public/logo512.png -------------------------------------------------------------------------------- /client/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 | -------------------------------------------------------------------------------- /client/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /client/src/App.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Raleway:wght@300&display=swap'); 2 | 3 | *{ 4 | padding: 0; 5 | margin:0 ; 6 | font-family: 'Raleway', sans-serif; 7 | outline: none; 8 | } 9 | 10 | body{ 11 | background-color: rgb(32, 32, 32); 12 | } 13 | :root { 14 | --main-bg-color: coral; 15 | --main-txt-color: blue; 16 | --width: 200px; 17 | } 18 | .webName{ 19 | /* text-align: center; */ 20 | display: inline-block; 21 | 22 | position: relative; 23 | left:10vw; 24 | color: white; 25 | font-size: 80px; 26 | margin:20px; 27 | } 28 | .container{ 29 | display:flex; 30 | flex-direction: column; 31 | justify-content: center; 32 | align-items: center; 33 | } 34 | .page{ 35 | background-color: aliceblue; 36 | width: 80vw; 37 | color:black; 38 | box-shadow: 0px 0px 15px white; 39 | border-radius: 5px ; 40 | margin: 0px 0px 50px; 41 | } 42 | 43 | .title{ 44 | text-align: center; 45 | margin-top: 30px; 46 | font-size:60px; 47 | text-decoration: underline; 48 | 49 | } 50 | p{ 51 | margin: 20px 100px; 52 | } 53 | 54 | .secondTitle{ 55 | background-color: rgb(32, 32, 32); 56 | border-radius: 10px; 57 | margin: 20px 100px 0px 100px; 58 | display: inline-block; 59 | padding:5px; 60 | color:white; 61 | font-weight: bold; 62 | } 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /client/src/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Suspense, lazy } from "react"; 3 | import "./App.css"; 4 | import Article from "./components/Article"; 5 | import ErrorBoundary from "./components/ErrorBoundary"; 6 | const Comments = lazy(() => import("./components/Comments")); 7 | 8 | const Loading = () =>
Loading . . .
; 9 | 10 | function App() { 11 | return ( 12 | <> 13 |

BiLA BLOG

14 |
15 |
16 |
17 |
18 | }> 19 | 20 | 21 | 22 | 23 |
24 | 25 | ); 26 | } 27 | 28 | export default App; 29 | -------------------------------------------------------------------------------- /client/src/components/Article.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export default function Article() { 4 | return ( 5 | <> 6 |

7 | How To Use Refs
8 | In React With Hooks 9 |

10 |

11 | Refs are probably the most misunderstood and misused part of React. All too often, I 12 | see developers using refs to manipulate the DOM directly or work around React in 13 | someway which makes working with React much harder. In this article I am going to go 14 | over everything you need to know about refs in order to help you never make those 15 | ref mistakes. 16 |

17 |

useRef

18 |

19 | In order to work with refs in React you need to first initialize a ref which is what 20 | the useRef hook is for. This hook is very straightforward, and takes an initial 21 | value as the only argument. 22 |

23 | 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /client/src/components/Comments.css: -------------------------------------------------------------------------------- 1 | .commentsContainer{ 2 | background-color: rgb(134, 134, 134); 3 | /* height: 100vh; */ 4 | width: 80vw; 5 | color:black; 6 | box-shadow: 0px 0px 15px white; 7 | border-radius: 5px ; 8 | display:flex; 9 | flex-direction: column; 10 | /* justify-content: center; */ 11 | align-items: center; 12 | margin-bottom:50px; 13 | } 14 | 15 | .newCommentContainer{ 16 | display:flex; 17 | flex-direction: column; 18 | background-color: rgb(189, 189, 189); 19 | border-radius: 5px ; 20 | margin:20px; 21 | width: 60vw; 22 | 23 | } 24 | .writeNewTitle{ 25 | margin: 10px 0px 0px 20px ; 26 | } 27 | .newCommentName{ 28 | margin: 20px 0px 0px 20px ; 29 | height: 50px; 30 | width: 250px; 31 | overflow: hidden; 32 | resize: none; 33 | padding:20px; 34 | box-sizing: border-box; 35 | border-radius:10px; 36 | border: 1px solid black; 37 | } 38 | .newCommentBody{ 39 | margin: 20px ; 40 | width: 55vw; 41 | resize: vertical; 42 | padding:20px; 43 | box-sizing: border-box; 44 | border-radius:10px; 45 | border: 1px solid black; 46 | } 47 | .submit{ 48 | margin:10px; 49 | width:120px; 50 | font-size: 30px; 51 | } -------------------------------------------------------------------------------- /client/src/components/Comments.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useRef } from "react"; 2 | import SingleComment from "./SingleComment"; 3 | import timeFunc from "./timeFunc"; 4 | 5 | import "./Comments.css"; 6 | 7 | export default function Comments() { 8 | const [comments, setComments] = useState([ 9 | { name: "Alexei Ryadov", time: "29.06.2018 20:22", body: "good job" }, 10 | { name: "Good feedback", time: "29.06.2020 20:22", body: "I Really like this blog" }, 11 | ]); 12 | const name = useRef(); 13 | const body = useRef(); 14 | 15 | const submitFunc = () => { 16 | if (body.current.value && name.current.value) { 17 | const newObj = { 18 | name: name.current.value, 19 | body: body.current.value, 20 | time: timeFunc(), 21 | }; 22 | name.current.value = ""; 23 | body.current.value = ""; 24 | 25 | setComments((prev) => [...prev, newObj]); 26 | } 27 | }; 28 | const createError = () => { 29 | setComments({}); 30 | }; 31 | const ChangeFocus = (e, field) => { 32 | if (e.keyCode === 13) { 33 | body.current.focus(); 34 | } 35 | }; 36 | return ( 37 |
38 | {comments.map((obj) => { 39 | return ; 40 | })} 41 | 42 |
43 |

Write new comment :

44 |