Giter VIP home page Giter VIP logo

js30_reactandstyledcomponents's Introduction

01 Drum Kit: 31 Dec 2020

Goal: build with modern REACT with HOOKS. Use cssinjs (JSS) for styles react, with hooks JSS - can use template strings to write actual CSS!! Will do this

  • used usedEffect [] with return to set 'app styles' on render. this is in place of traditional html and body styles
  • used 'new Audio' for first time

next day review/refactor

  • new bg, tinker a little with styles

02 Clock: 01 Jan 2021

React JSS - using template strings! new thing: passing some styles to children

  • in CSS: the "rem" unit (ie root em) is used to set dims based on the root elements font size. The root element is usually . This helps to keep everything consistent.
  • in CSS: The box-sizing property allows us to include the padding and border in an element's total width and height. boxSizing: 'border-box'

? best way to do code checking/linting for JSS -> using css template strings? ? how to pass props to template sting stylea?

TODOs [] hour labels on clock (clockface border) [x] different color or length hands [x] bug: when seconds hand gets to 90deg it flickers. why? (probably bezier transition func jump)

next day review

  • definitely use styled-components in place of react-jss [] BUT need to learn how to pass props (todo: in HourMark component) [] work out how to stop the hour marks stop rerendering

03 CSS Variables. 02 Jan 2021

this will be interesting to port to react. I will treat it as a styled-copoments exercise

used react state hooks.

Learned

  • document.documentElement accesses the :root. can update css vars here
  • styled-components has a global style method for the root
  • #fff8e7; cosmic latte. but i like TimGold #E1b01d on a #193549 bg
const GlobalStyle = createGlobalStyle`
  :root {
    --base: #E1b01d; /* #fff8e7;  cosmic latte */
    --blur: 3px;
    --spacing: 10px;
  }
`

04 Array Methods

filter, map, sort, reduce

05 Flex gallery

starting to get into the weeds with styled-components. Using useState hook to track local 'isActive state. use transition delay prop(type duration delay) to stagger transitions

08 HTML5 Canvas

when you use the useEffect hook to set eventListeners on render, they only have a snapshot of state at render. Must use useRef hook to give the listener handle functions access to the current state. "Click ad drag functionality"

10

Array.prototype.indexOf.call(nodelist, el) useRef hook again in eventlistener that is set on initial render

11

12

13

14

ways to copy an array (since references to an array are mutable) that leave original array untouched const arr1 = [1,2,3,4,5] const arr2 = arr1.slice() const arr3 = [].concat(arr1) const arr4 = [...arr1] const arr5 = Array.from(arr1) arrX[1] = 'XXX' //original arr1 is ok

ways to copy obj that leave original immuted const person = { name: 'Tim', age: 32 } const p2 = Object.assign({}, person, { number: 99, age: 12}) const p3 = {...person, fruit: 'banana'} const p4 = {...person, age: 666, fruit: 'banana'} // same prop again after spreading will override in the copy

NOTE: shallow! only ever one level deep const fruits = { type: 'tree', fruit1: { name: 'apple', num: 3 } } const f2 = {...fruits} f2.fruit1.num = 7 // OHNO! also changes fruits.fruit1.num only goes 1 level deep

look up cloneDeep online, or hack way

const f3 = JSON.parse(JSON.stringify(fruits)) f3.fruit1.num = 99

// JSON parse and stringify will turn the obj into a string (new ref) and then back into an obj - kills any refs to original obj

yarn start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

yarn test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

yarn build

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.

yarn eject

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.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

yarn build fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.