├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── src ├── api │ └── posts.js ├── Footer.js ├── Feed.js ├── About.js ├── Missing.js ├── index.js ├── Header.js ├── Home.js ├── Post.js ├── hooks │ ├── useWindowSize.js │ └── useAxiosFetch.js ├── Nav.js ├── NewPost.js ├── PostPage.js ├── EditPost.js ├── App.js └── index.css ├── .gitignore ├── README.md ├── package.json └── data └── db.json /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitdagray/react_custom_hooks/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitdagray/react_custom_hooks/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitdagray/react_custom_hooks/HEAD/public/logo512.png -------------------------------------------------------------------------------- /src/api/posts.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | export default axios.create({ 4 | baseURL: 'http://localhost:3500' 5 | }); -------------------------------------------------------------------------------- /src/Footer.js: -------------------------------------------------------------------------------- 1 | const Footer = () => { 2 | const today = new Date(); 3 | return ( 4 | 7 | ) 8 | } 9 | 10 | export default Footer 11 | -------------------------------------------------------------------------------- /src/Feed.js: -------------------------------------------------------------------------------- 1 | import Post from './Post'; 2 | 3 | const Feed = ({ posts }) => { 4 | return ( 5 | <> 6 | {posts.map(post => ( 7 | 8 | ))} 9 | 10 | ) 11 | } 12 | 13 | export default Feed 14 | -------------------------------------------------------------------------------- /src/About.js: -------------------------------------------------------------------------------- 1 | const About = () => { 2 | return ( 3 |
4 |

About

5 |

This blog app is a project in the Learn React tutorial series.

6 |
7 | ) 8 | } 9 | 10 | export default About 11 | -------------------------------------------------------------------------------- /src/Missing.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'react-router-dom'; 2 | 3 | const Missing = () => { 4 | return ( 5 |
6 |

Page Not Found

7 |

Well, that's disappointing.

8 |

9 | Visit Our Homepage 10 |

11 |
12 | ) 13 | } 14 | 15 | export default Missing 16 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import { BrowserRouter as Router, Route } from 'react-router-dom'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | 11 | 12 | , 13 | document.getElementById('root') 14 | ); 15 | 16 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/Header.js: -------------------------------------------------------------------------------- 1 | import { FaLaptop, FaTabletAlt, FaMobileAlt } from 'react-icons/fa'; 2 | 3 | const Header = ({ title, width }) => { 4 | return ( 5 |
6 |

{title}

7 | {width < 768 ? 8 | : width < 992 ? 9 | : } 10 |
11 | ) 12 | } 13 | 14 | export default Header 15 | -------------------------------------------------------------------------------- /src/Home.js: -------------------------------------------------------------------------------- 1 | import Feed from './Feed'; 2 | 3 | const Home = ({ posts, fetchError, isLoading }) => { 4 | return ( 5 |
6 | {isLoading &&

Loading posts...

} 7 | {!isLoading && fetchError &&

{fetchError}

} 8 | {!isLoading && !fetchError && (posts.length ? :

No posts to display.

)} 9 |
10 | ) 11 | } 12 | 13 | export default Home 14 | -------------------------------------------------------------------------------- /src/Post.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'react-router-dom'; 2 | 3 | const Post = ({ post }) => { 4 | return ( 5 |
6 | 7 |

{post.title}

8 |

{post.datetime}

9 | 10 |

{ 11 | (post.body).length <= 25 12 | ? post.body 13 | : `${(post.body).slice(0, 25)}...` 14 | }

15 |
16 | ) 17 | } 18 | 19 | export default Post 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/hooks/useWindowSize.js: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from "react"; 2 | 3 | const useWindowSize = () => { 4 | const [windowSize, setWindowSize] = useState({ 5 | width: undefined, 6 | height: undefined 7 | }); 8 | 9 | useEffect(() => { 10 | 11 | const handleResize = () => { 12 | setWindowSize({ 13 | width: window.innerWidth, 14 | height: window.innerHeight 15 | }); 16 | } 17 | 18 | handleResize(); 19 | 20 | window.addEventListener("resize", handleResize); 21 | 22 | return () => window.removeEventListener("resize", handleResize); 23 | }, []) 24 | 25 | return windowSize; 26 | } 27 | 28 | export default useWindowSize; 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # "React JS - Custom Hooks" 2 | 3 | ✅ [Check out my YouTube Channel with all of my tutorials](https://www.youtube.com/DaveGrayTeachesCode). 4 | 5 | **Description:** 6 | 7 | This repository shares the code applied during the Youtube tutorial. The tutorial is part of a [Learn React Playlist](https://www.youtube.com/playlist?list=PL0Zuz27SZ-6PrE9srvEn8nbhOOyxnWXfp) on my channel. 8 | 9 | [YouTube Tutorial](https://youtu.be/tBuceoEGFhI) for this repository. 10 | 11 | I suggest completing my [8 hour JavaScript course tutorial video](https://youtu.be/EfAl9bwzVZk) if you are new to Javascript. 12 | 13 | ### Academic Honesty 14 | 15 | **DO NOT COPY FOR AN ASSIGNMENT** - Avoid plagiargism and adhere to the spirit of this [Academic Honesty Policy](https://www.freecodecamp.org/news/academic-honesty-policy/). 16 | -------------------------------------------------------------------------------- /src/Nav.js: -------------------------------------------------------------------------------- 1 | import { Link } from 'react-router-dom'; 2 | 3 | const Nav = ({ search, setSearch }) => { 4 | return ( 5 | 22 | ) 23 | } 24 | 25 | export default Nav 26 | -------------------------------------------------------------------------------- /src/NewPost.js: -------------------------------------------------------------------------------- 1 | const NewPost = ({ 2 | handleSubmit, postTitle, setPostTitle, postBody, setPostBody 3 | }) => { 4 | return ( 5 |
6 |

New Post

7 |
8 | 9 | setPostTitle(e.target.value)} 15 | /> 16 | 17 |