Working Application - Deployed
- backroads-html - working html/css/javascript project (contains assets)
- final(complete source code) - working react application
- navigate to the folder
- run 'npm install'
- once the dependencies are installed run 'npm start'
Find the Content Useful? You can always buy me a coffee
- install
npx create-react-app@latest backroads-app
- run dev server
npm start
- index.js
import React from 'react'
import ReactDOM from 'react-dom/client'
// styles (typically global)
import './index.css'
// convention to name it App and setup in a separate file
import App from './App'
// import report web vitals
import reportWebVitals from './reportWebVitals'
// StrictMode
// StrictMode is a tool for highlighting potential problems in an application.Activates additional checks and warnings for its descendants.Runs only in Development, does not impact the production build. RENDERS TWICE !!! Possible to remove.
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
)
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals()
-
remove in src
- setupTests.js
- reportWebVitals.js
- App.test.js
-
be careful with multiple css files
App.js
function App() {
return <h1>backroads app</h1>
}
export default App
- remove
- remove logo.svg
- App.css
-
public/index.html
- change title
- copy/paste font-awesome link (from html project)
-
index.css
- copy/paste css (from html project - css/styles.css)
- error in line 209, just comment out for now
@media screen and (min-width: 768px) {
/* .hero {
background: linear-gradient(rgb(44, 174, 186, 0.7), rgba(0, 0, 0, 0.7)),
url('../images/main.jpeg') center/cover no-repeat;
} */
}
- src folder
- copy/paste images folder (from html project)
- move favicon.ico to public
- App.js
- refactor to <React.Fragment>
- copy/paste all the content within body tags, up to <script> (index.html)
- select all "class" instances and refactor to "className" (CMD + D)
- fix the comment bug (remove or comment out)
- don't worry about - Using target="_blank" without rel="noreferrer" warning, will fix it later
- move README.md from final to current project
- in src create components folder
- in the components create following files
- Navbar.js
- Hero.js
- About.js
- Services.js
- Tours.j
- Footer.js
- setup components with default export (snippet - rafce)
- carefully move the code from App.js into components (files)
- hint - look for navbar, footer and section tags
- App.js should be empty
- import and render all components in App.js (try auto imports)
- result is going to be the same, it's just easier to manage the code
- again, it's just my preference to split up code in such way. You can split it up in any way that makes the most sense to you.
- first let's fix the image (logo)
- setup import from images and update source
// import
import logo from '../images/logo.svg'
// JSX
;<img src={logo} className='nav-logo' alt='backroads' />
- html/css feature
<!-- link -->
<a href="#services"> services </a>
<!-- element -->
<section id="services"></section>
html {
scroll-behavior: smooth;
}
.section {
/* navbar height */
scroll-margin-top: 4rem;
}
- refactor repeating code
<li>
<a href='#home' className='nav-link'>
home
</a>
</li>
- figure out which data is repeating hint (href, text )
- in src create data.js and setup a structure
- (hint - [{property:value},{property:value}])
- export/import iterate over the list,return elements and inject data
export const pageLinks = [
{ id: 1, href: '#home', text: 'home' },
{ id: 2, href: '#about', text: 'about' },
{ id: 3, href: '#services', text: 'services' },
{ id: 4, href: '#tours', text: 'tours' },
]
import { pageLinks } from '../data'
{
pageLinks.map((link) => {
return (
<li key={link.id}>
<a href={link.href} className='nav-link'>
{link.text}
</a>
</li>
)
})
}
- repeat the same steps (as with page links)
- add rel='noreferrer'
{
socialLinks.map((link) => {
const { id, href, icon } = link
return (
<li key={id}>
<a href={href} target='_blank' rel='noreferrer' className='nav-icon'>
<i className={icon}></i>
</a>
</li>
)
})
}
- change title or text (optional)
- fix the image (path in css)
- fix the image (hint - just like with logo in the navbar)
- in components create Title.js
- get the structure from one of the sections
- setup two props
- replace in About, Services, Tours
const Title = ({ title, subTitle }) => {
return (
<div className='section-title'>
<h2>
{title} <span>{subTitle}</span>
</h2>
</div>
)
}
export default Title
About.js
// import
import Title from './Title'
// display
;<Title title='about' subTitle='us' />
- refactor repeating code (hint - just like with page and social links)
- setup data, export/import, iterate
data.js
export const services = [
{
id: 1,
icon: 'fas fa-wallet fa-fw',
title: 'saving money',
text: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.Asperiores, officia',
},
// rest of the objects
]
Services.js
import Title from './Title'
import { services } from '../data'
const Services = () => {
return (
<section className='section services' id='services'>
<Title title='our' subTitle='services' />
<div className='section-center services-center'>
{services.map((service) => {
const { id, icon, title, text } = service
return (
<article className='service' key={id}>
<span className='service-icon'>
<i className={icon}></i>
</span>
<div className='service-info'>
<h4 className='service-title'>{title}</h4>
<p className='service-text'>{text}</p>
</div>
</article>
)
})}
</div>
</section>
)
}
export default Services
- refactor repeating code
- refactor repeating code
- re-use page and social links
- in the provide current year (hint - {})
- in components create PageLinks.js
- import pageLinks
- return the entire list and replace current setup in Navbar, Footer
- "gotcha"
- the more "moving parts" you will have the harder it's going to be to manage
- my personal preference, if possible just use data
- create more components (essentially, split up the code more)
- find all map methods and move elements to separate components
- By the end of the video you should have four additional components
- Tour.js
- Service.js
- SocialLink.js
- PageLink.js
-
fix warnings (About Section)
-
netlify account
-
github account
-
basic git commands :
- remove existing git repo
- Mac : rm -rf .git
- Windows : rmdir -Force -Recurse .git
- Windows : rd /s /q .git Windows commands were shared by students and I have not personally tested them.
- setup new repo
- git init create an empty git repository
- git add adds new or changed files in your working directory to the Git staging area
- git add . adds entire project apart from files/directories specified in .gitignore
- git commit -m "first commit" A shortcut command that immediately creates a commit with a passed commit message.
- push to github git remote add origin git@github.com:your-profile/repo-name.git git branch -M main git push -u origin main
- remove existing git repo
- don't need to keep project locally
- automatic builds
- Netlify treats warnings as errors
package.json
"scripts": {
"start": "react-scripts start",
"build": "CI= react-scripts build",
"local-build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.
The page will reload when you make changes.
You may also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can't go back!
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.
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.
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.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify