Todo App Using React Hooks
JavaScript
March 14th, 2020
Hook 釋放於 16.8版。它可以讓你在不編寫class的情況下使用state以及其他的React特性。
而為甚麼要使用React Hooks呢? 大家可以到以下連結來看看大神們的說法
Making Sense of React Hooks
React: Class Component vs Functional Component
Huge components that are hard to refactor and test.
Duplicated logic between different components and lifecycle methods.
Complex patterns like render props and higher-order components.
1.2kb against 97 bytes to render 10,000 element
我透過function component將Todo App切成三個區塊 App()
, TodoForm()
, Todo()
。話不多說,大家到我的codeSandbox看看我是怎麼利用React hooks的useState()
寫出基本的todolist吧