React, 翻譯文章, 如何在元件中取得 DOM 元素
“Redux is a predictable state container for JavaScript apps.”
“Flux 是一種單向資料流的設計模式,幫助你撰寫有條理的前端架構。”
我們知道元件會有狀態的變化,且上層元件也可以傳遞參數給下層元件,來讓元件產生變化。
在一個複雜的應用程式中,你通常會有攔截變化(不論是元件重新渲染、狀態更新、上層元件傳遞新的參數),並且進行後續相對應行為的需求。
因此,得知元件何時變化,就變得非常重要!在 React 中,元件的 class 有相對應的 method 可以幫助你攔截這些變化。
我們知道在 React 世界中,一眼望去就是滿街的元件。而元件通常就做兩件事情:顯示資料、與用戶互動及接受用戶的輸入資料。
今天我們將討論接收用戶資料的 React 元件,如果你有接觸過 HTML,這些元件基本上就是 <input>, <textarea>, <option> 等 tag,只是微微的不太一樣。
在 React 的世界中,元件的資料來源有兩種方式:
在前幾篇文章中,我們了解 React 最重要的思維是「元件設計」。它讓我們方便得透過重複利用和組合元件,作成一個複雜的應用程式,這樣的開發體驗就如同你小時候疊樂高般。
一個 React 元件,可以透過參數(props)來改變自身的行為和樣式。
假設我們的網站真的是由樂高堆疊起來的,身為前端工程師的我們,該設計多少個元件呢?