├── .gitignore ├── LICENSE ├── README.md ├── gatsby-browser.js ├── gatsby-config.js ├── gatsby-node.js ├── gatsby-ssr.js ├── package.json ├── src ├── components │ ├── app-container.js │ ├── comments.js │ ├── header.js │ ├── image.js │ ├── layout.css │ ├── layout.js │ └── seo.js ├── context │ └── comments.js ├── hooks │ ├── use-comments.js │ └── use-site-metadata.js ├── images │ ├── gatsby-astronaut.png │ └── gatsby-icon.png └── pages │ ├── 404.js │ ├── index.js │ └── page-2.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # dotenv environment variables file 55 | .env 56 | 57 | # gatsby files 58 | .cache/ 59 | public 60 | 61 | # Mac files 62 | .DS_Store 63 | 64 | # Yarn 65 | yarn-error.log 66 | .pnp/ 67 | .pnp.js 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 Jason Lengstorf 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Hooks and How to Use Them With Gatsby 2 | 3 | Demo code built with Sidhartha Chatterjee to show off how React Hooks work and how to use them with Gatsby. 4 | 5 | [Watch us build this code live!](https://youtu.be/asrdFuAxPaU) 6 | -------------------------------------------------------------------------------- /gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | import React from 'react'; 7 | import AppContainer from './src/components/app-container'; 8 | 9 | // You can delete this file if you're not using it 10 | export const wrapRootElement = ({ element }) => ( 11 | {element} 12 | ); 13 | -------------------------------------------------------------------------------- /gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | siteMetadata: { 3 | title: `Gatsby Default Starter`, 4 | description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`, 5 | author: `@chatsidhartha` 6 | }, 7 | plugins: [ 8 | `gatsby-plugin-react-helmet`, 9 | { 10 | resolve: `gatsby-source-filesystem`, 11 | options: { 12 | name: `images`, 13 | path: `${__dirname}/src/images` 14 | } 15 | }, 16 | `gatsby-transformer-sharp`, 17 | `gatsby-plugin-sharp`, 18 | { 19 | resolve: `gatsby-plugin-manifest`, 20 | options: { 21 | name: `gatsby-starter-default`, 22 | short_name: `starter`, 23 | start_url: `/`, 24 | background_color: `#663399`, 25 | theme_color: `#663399`, 26 | display: `minimal-ui`, 27 | icon: `src/images/gatsby-icon.png` // This path is relative to the root of the site. 28 | } 29 | } 30 | // this (optional) plugin enables Progressive Web App + Offline functionality 31 | // To learn more, visit: https://gatsby.app/offline 32 | // 'gatsby-plugin-offline', 33 | ] 34 | }; 35 | -------------------------------------------------------------------------------- /gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-hooks-gatsby", 3 | "private": true, 4 | "description": "Demo code built with Sidhartha Chatterjee to show off how React Hooks work and how to use them with Gatsby.", 5 | "version": "0.1.0", 6 | "author": "Jason Lengstorf ", 7 | "dependencies": { 8 | "gatsby": "^2.1.2", 9 | "gatsby-image": "^2.0.29", 10 | "gatsby-plugin-manifest": "^2.0.17", 11 | "gatsby-plugin-offline": "^2.0.23", 12 | "gatsby-plugin-react-helmet": "^3.0.6", 13 | "gatsby-plugin-sharp": "^2.0.20", 14 | "gatsby-source-filesystem": "^2.0.20", 15 | "gatsby-transformer-sharp": "^2.1.13", 16 | "prop-types": "^15.7.2", 17 | "react": "^16.8.1", 18 | "react-dom": "^16.8.1", 19 | "react-helmet": "^5.2.0" 20 | }, 21 | "keywords": [ 22 | "gatsby" 23 | ], 24 | "license": "MIT", 25 | "scripts": { 26 | "build": "gatsby build", 27 | "develop": "gatsby develop", 28 | "start": "npm run develop", 29 | "serve": "gatsby serve", 30 | "test": "echo \"Write tests! -> https://gatsby.app/unit-testing\"" 31 | }, 32 | "repository": { 33 | "type": "git", 34 | "url": "https://github.com/jlengstorf/react-hooks-gatsby" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/components/app-container.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import CommentsContext from '../context/comments'; 3 | import useComments from '../hooks/use-comments'; 4 | 5 | const AppContainer = ({ children }) => { 6 | const { comment, comments, onChange, onSubmit } = useComments(); 7 | 8 | return ( 9 | 10 | {children} 11 | 12 | ); 13 | }; 14 | 15 | export default AppContainer; 16 | -------------------------------------------------------------------------------- /src/components/comments.js: -------------------------------------------------------------------------------- 1 | import React, { useContext } from 'react'; 2 | import CommentsContext from '../context/comments'; 3 | 4 | const Comments = () => { 5 | const { comment, comments, onChange, onSubmit } = useContext(CommentsContext); 6 | 7 | return ( 8 |
9 |
10 |