generated from btholt/next-course-starter
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from btholt/dustin/edits
spelling, links, etc
- Loading branch information
Showing
29 changed files
with
160 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,31 +17,29 @@ keywords: | |
|
||
Let's start by writing pure React. No compile step. No JSX. No Babel. No Webpack or Vite. Just some JavaScript on a page. | ||
|
||
Let's start your project. Create your project directory. I'm going to call mine `pizza` since we're going to be building a pizza ordering system throughout this course. Create an index.html and put it into a `src/` directory inside of your project folder. In index.html put: | ||
Let's start your project. Create your project directory inside the repo. I'm going to call mine `pizza` since we're going to be building a pizza ordering system throughout this course. Open that directory in VS Code or your editor of choice. Create an index.html and add this markup: | ||
|
||
```javascript | ||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<link rel="stylesheet" href="./style.css"> | ||
<title>Adopt Me</title> | ||
</head> | ||
|
||
<body> | ||
<div id="root">not rendered</div> | ||
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script> | ||
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script> | ||
<script src="./src/App.js"></script> | ||
</body> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<title>Padre Gino's</title> | ||
</head> | ||
|
||
<body> | ||
<div id="root">not rendered</div> | ||
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script> | ||
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script> | ||
<script src="./src/App.js"></script> | ||
</body> | ||
</html> | ||
``` | ||
|
||
Let's run this. We could open it directly in our browser but I like using [serve][serve]. Run `npx serve` and open localhost:3000 in your browser. | ||
Let's run this. We could open it directly in our browser but I like using [serve][serve]. Run `npx serve` and open [http://localhost:3000/]() in your browser. | ||
|
||
- Pretty standard HTML5 document. If this is confusing, I teach another course called [Intro to Web Dev][webdev] that can help you out. | ||
- We're adding a root div. We'll render our React app here in a sec. It doesn't _have_ to be called root, just a common practice. | ||
|
@@ -52,7 +50,7 @@ Let's run this. We could open it directly in our browser but I like using [serve | |
|
||
> Let's add some style! [Click here][style] to get the stylesheet for this course. Make a file called style.css in src/ and paste the previous file there. If you follow along with the course and use the same class names, the styles will be applied for you automatically. This isn't a course on CSS so I make no assertion it's any good! | ||
Make a new directory calle src and a new file called App.js in that directory and put this in there. | ||
Make a new directory called `src` and a new file called `App.js` in that directory and put this in there. | ||
|
||
```javascript | ||
const App = () => { | ||
|
@@ -83,5 +81,5 @@ This is about the simplest React app you can build. | |
> ReactDOM.createRoot is a new API as of React v18. The old `ReactDOM.render` is still available (and deprecated) but it'll render your app in "legacy" mode which won't use all the fun new features packed into React v18 | ||
[webdev]: https://frontendmasters.com/courses/web-development-v3/ | ||
[style]: https://raw.githubusercontent.com/btholt/citr-v9-project/master/01-no-frills-react/src/style.css | ||
[style]: https://github.com/btholt/citr-v9-project/blob/main/api/public/style.css | ||
[serve]: https://github.com/vercel/serve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,17 @@ keywords: | |
- Brian Holt | ||
--- | ||
|
||
## ESLint | ||
|
||
On top of Prettier which takes of all the formatting, you may want to enforce some code styles which pertain more to usage: for example you may want to force people to never use `with` which is valid JS but ill advised to use. [ESLint][eslint] comes into play here. It will lint for this problems. | ||
|
||
First of all, run `npm install -D [email protected] [email protected] [email protected]` to install eslint in your project development dependencies. Then you may configure its functionalities. | ||
First of all, run `npm install -D [email protected] [email protected] [email protected]` to install ESLint in your project development dependencies. Then you may configure it. | ||
|
||
There are dozens of preset configs for ESLint and you're welcome to use any one of them. The [Airbnb config][airbnb] is very popular, as is the standard config (both of which I taught in previous versions of this class). I'm going to use a looser one for this class: the recommended JS config from ESLint. Let's create an `eslint.config.mjs` file to start linting our project. | ||
|
||
> We're using .mjs (module JS) because we want to use import/export for modules instead of require/ | ||
> We're using .mjs (module JS) because we want to use import/export for modules instead of require | ||
Create this file called `eslint.config.mjs`. | ||
Add this to the `eslint.config.mjs` file: | ||
|
||
```js | ||
import js from "@eslint/js"; | ||
|
@@ -46,9 +48,9 @@ export default [ | |
]; | ||
``` | ||
|
||
- ESLint changed a lot with version 9. In previous versions of this course we did used the JSON version of configuration and that's no longer supported; you _have_ to do their newer "flat" version of config (honestly it is better.) | ||
- The `/** @type {import('eslint').Linter.Config[]} */` is a VS Code / TypeScript trick to be able to do autocompletions on the config object. Super helpful to have the types available right in VS Code. It's not required. | ||
- [globals][globals] is a package that is just a big JSON file of what's available in each environment. We're going to be in Node.js and Browser environments so we grabbed those two. If I was being a bit more discerning I'd carefully only apply browser configs to browser files and node configs to Node.js files. | ||
- ESLint changed a lot with version 9. In previous versions of this course we used the JSON version of configuration which is no longer supported. You _have_ to do their newer "flat" version of config (honestly it is better.) | ||
- The `/** @type {import('eslint').Linter.Config[]} */` is a VS Code / TypeScript trick to be able to do auto-completions on the config object. Super helpful to have the types available right in VS Code. It's not required. | ||
- [globals][globals] is a package that is just a big JSON file of what's available in each environment. We're going to be in Node.js and Browser environments so we grabbed those two. If I was being a bit more discerning I'd carefully only apply browser configs to browser files and Node configs to Node.js files. | ||
- The config objects are applied in order. We did ESLint's JS config first, and then our custom one so we can overwrite it where we want to, and then the Prettier one should always come last as all it does is turn off rules that Prettier itself does; it doesn't add anything. | ||
|
||
This is a combination of the recommended configs of ESLint and Prettier. This will lint for both normal JS stuff as well as JSX stuff. Run `npx eslint` now and you should see we have a few errors. Run it again with the `--fix` flag and see it will fix some of it for us! Go fix the rest of your errors and come back. Let's go add this to our npm scripts. | ||
|
@@ -77,3 +79,4 @@ Two projects to watch going forward here: [Biome][biome] (formerly called Rome) | |
[vscode]: https://code.visualstudio.com/ | ||
[biome]: https://biomejs.dev/ | ||
[oxlint]: https://oxc.rs/docs/guide/usage/linter.html | ||
[globals]: https://www.npmjs.com/package/globals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.