2019年1月28日 星期一

Redux Thunk

What's a thunk?

Thunk廣泛指的是: 延後執行的wrapper。

// calculation of 1 + 2 is immediate
// x === 3
let x = 1 + 2;

// calculation of 1 + 2 is delayed
// foo can be called later to perform the calculation
// foo is a thunk!
let foo = () => 1 + 2;

Thunk in Redux:

在Redux中的Thunk應用則是指"延後執行Dispatch"。

Thunk middleware 會幫助dispatch async action, 等待action 執行完畢後再 dispatch 內容至store,達到非同步。

這個dispatch 的內容並非帶值的 action,而是一個async function,執行完畢前皆未有值;執行完畢後,此async function 將另外寫一個dispatch,自行再次dispatch至store (這次的dispatch就如同一般的同步disptch function一樣)。

2019年1月22日 星期二

React: Useful Resource

Styling:
- semantic ui (cdn: https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css )


Fake data:
- faker.js (npm install --save faker)
- JSONPlaceholder


Logical process:
- Lo (npm install --save lodash)


Frequent Use:
- redux
- react-redux
- axios
- redux-thunk
- react-router-dom
- redux-form