npm install -g gatsby-cli<\/code><\/pre>\n\n\n\nInstall gatsby, react and react-dom<\/p>\n\n\n\n
yarn add gatsby react react-dom<\/code><\/pre>\n\n\n\nEdit the scripts section of the package.json<\/code> file to add a script for develop<\/code>.<\/p>\n\n\n\n\"scripts\": {\n \"develop\": \"gatsby develop\"\n }<\/code><\/pre>\n\n\n\nGatsby projects need a special configuration file called, gatsby-config.js<\/code>. Please create a file named, gatsby-config.js<\/code> at the root of the project folder with the following content,<\/p>\n\n\n\nmodule.exports = {\n \/\/ keep it empty \n}<\/code><\/pre>\n\n\n\nLet\u2019s create our first page with Gatsby. Create a folder named, src<\/code> at the root of the project folder. Create a subfolder named pages<\/code> under src<\/code>. Create a file named, index.js<\/code> under src\/pages<\/code> with the following content:<\/p>\n\n\n\nimport React, { useEffect, useState } from 'react'; \n \nexport default () => { \n const [loading, setLoading ] = useState(false); \n const [shopnotes, setShopnotes] = useState(null); \n \n return (\n <> \n <h1>Shopnotes to load here...<\/h1>\n <\/> \n ) \n}\n<\/code><\/pre>\n\n\n\nLet’s run it. We generally need to use the command gatsby<\/code> develop to run the app locally. As we have to run the client side application with netlify functions, we will continue to use, netlify dev<\/code> command.<\/p>\n\n\n\nnetlify dev<\/code><\/pre>\n\n\n\nThat’s all. Try accessing the page at http:\/\/localhost:8888<\/code>. You should see something like this,<\/p>\n\n\n\n <\/figure>\n\n\n\nGatsby project build creates a couple of output folders which you may not want to push to the source code repository. Let us add a few entries to the .gitignore<\/code> file so that we do not get unwanted noise.<\/p>\n\n\n\nAdd .cache<\/code>, node_modules<\/code> and public<\/code> to the .gitignore<\/code> file. Here is the full content of the file:<\/p>\n\n\n\n.cache\npublic\nnode_modules\n*.env<\/code><\/pre>\n\n\n\nAt this stage, your project directory structure should match with the following:<\/p>\n\n\n\n <\/figure>\n\n\nThinking of the UI components<\/h4>\n\n\n We will create small logical components to achieve the ShopNote<\/code> user interface. The components are:<\/p>\n\n\n\nHeader:<\/strong> A header component consists of the Logo, heading and the create button to create a shopnote.<\/li>Shopenotes:<\/strong> This component will contain the list of the shop note (Note<\/code> component).<\/li>Note:<\/strong> This is individual notes. Each of the notes will contain one or more items.<\/li>Item:<\/strong> Each of the items. It consists of the item name and actions to add, remove, edit an item.<\/li><\/ul>\n\n\n\nYou can see the sections marked in the picture below:<\/p>\n\n\n\n <\/figure>\n\n\nInstall a few more dependencies<\/h4>\n\n\n We will install a few more dependencies required for the user interfaces to be functional and look better. Open a command prompt at the root of the project folder and install these dependencies,<\/p>\n\n\n\n
yarn add bootstrap lodash moment react-bootstrap react-feather shortid<\/code><\/pre>\n\n\nLets load all the Shop Notes<\/h4>\n\n\n We will use the Reactjs useEffect<\/code> hook to make the API call and update the shopnotes state variables. Here is the code to fetch all the shop notes. <\/p>\n\n\n\nuseEffect(() => {\n axios(\"\/api\/get-shopnotes\").then(result => {\n if (result.status !== 200) {\n console.error(\"Error loading shopnotes\");\n console.error(result);\n return;\n }\n setShopnotes(result.data.shopnotes);\n setLoading(true);\n });\n}, [loading]);<\/code><\/pre>\n\n\n\nFinally, let us change the return section to use the shopnotes data. Here we are checking if the data is loaded. If so, render the Shopnotes<\/code> component by passing the data we have received using the API.<\/p>\n\n\n\nreturn (\n <div className=\"main\">\n <Header \/>\n {\n loading ? <Shopnotes data = { shopnotes } \/> : <h1>Loading...<\/h1>\n }\n <\/div>\n); \n<\/code><\/pre>\n\n\n\nYou can find the entire index.js file code from here<\/a> The index.js<\/code> file creates the initial route(\/<\/code>) for the user interface. It uses other components like,