2021 第46週 學習記錄:CSS modules、React HOC、React router、debounce 與 throttle

總結

記錄 2021 年第 46 週學到的新東西:CSS modules、React Router、Debounce 與 Throttle

CSS modules

Adobe Magneto PWA docs: A CSS Module is a CSS file that defines class and animation names that are scoped locally by default. CSS modules do not have an official specification nor are they a browser feature. They are part of a compilation process that executes against your project to convert scoped classes and selectors into CSS files that the browser can parse and understand. Tools such as Webpack are used to perform this compilation process.

相關問題

試圖對 MUI 元件套用自定義的 CSS 樣式,確定語法與選擇器皆有正確撰寫,但樣式卻沒有套用到畫面上

React

Higher-Order function

Higher-Order function 是 function 回傳 function;而 higher-order component 也可用類似邏輯理解

// function return function
const add = (x) => (y) => (z) => x + y + z;
add(2)(3)(4); // 2+3+4 = 9

Higher-Order Components

React Official Docs: A higher-order component is a function that takes a component and returns a new component.

// component return component
const EnhancedComponent = higherOrderComponent(WrappedComponent);

React Router

strict, exact

Searching Debounce, Throttle

When a React component handles bursting events like window resize, scrolling, user typing into an input, etc. — it’s wise to soften the handlers of these events. Otherwise, when the handlers are invoked too often you risk making the application lagging or even unresponsive for a few seconds.

參考文章