11th Practical Class:
Getting Real!
Data Transformation
const newData = transformFn(data)
vanilla JS
- (
array.map()
,array.filter()
,{ ...a, b: 1 }
,Object.entries()
) 👍 good for basic usage 👍
- (
lodash
🤔 simple, but kind of outdated design 🤔
ramda
👍 recommended 👍
fp-ts
⚠️ 🤯 the best...
...but only for functional programmig lovers 🤯 ⚠️- like Elm/Haskell/OCaml/F#, but in TypeScript
React Newsletters
How to Create the Frontend:
Create React App
- no boilerplates!
react-scripts
- Create project:
npx create-react-app 4it580-cra
- add:
.editorconfig
- add
.prettierignore
- add
.prettierrc.yaml
- add
.env
- add
.nvmrc
...or use command: node --version > .nvmrc
- install prettier
- edit
"scripts"
section ofpackage.json
- install dependencies
- add
src/Routes.js
(more info about react-router
setup)
- change
src/App.js
- SWR (Stale While Revalidate):
- add
src/pages/HomePage.js
How to Create the Backend:
Backpack
Vanilla JS
- create
4it580-backend
folder
- create
package.json
- use
yarn init
(it will ask few questions and createpackage.json
for you) - or paste following:
- add Express.js
- create
src/index.js
- run the server
Add Backpack
("Create React App for backend")
- add backpack
- add
"scripts"
topackage.json
- run dev server
How to Create Server-Side Rendering:
Next.js
create new project
deployment:
alternative to Next.js is Gatsby.js
- both are good for static sites and with server-side rendering (good SEO, works without JS)
- Next.js is usable for more aplication types (e.g. e-shops, dynamic apps, data from DB)
- it's also more flexlible
- it could require bit more work in some cases
- Gatsby is more focuset on static sites (data from static files in Git repo)
- some usecases are easier (e.g. blog)