前言:在大型項目中,直接把action寫在組件中,會很散亂,改和找都不好,所以如果action多了的話,建議在 /src/store/actionCreator.js
中統一管理
1、actionCreator.js
- 導出一個
函數
- 傳入的
參數是value
return一個對象
export const [xxxxxAction] = (value) => ({
type: [xxx],
value
})
export ....
2、在需要的組件中引入actionCreator.js
import { [xxxxxAction] } from './src/store/actionCreator'
const action = [xxxxxAction]( [value] )
store.dispatch(action)