我正在使用thunk来获取异步功能,并且无论出于什么原因,action.type返回的都是persist / REHYDRATE而不是FETCH_PLAYERS,我该如何进入FETCH_PLAYERS切换大小写的情况?完整的代码: https://snack.expo.io/@haosmark/kw-companion
我正在调用在组件启动时获取播放器列表的函数
componentDidMount() {
this.props.fetchPlayerList
}
这是我的动作文件的样子:
import { FETCH_PLAYERS } from './types'
import { fetchDataAsync } from '../../api'
const data = await fetchDataAsync()
export const fetchPlayerList = () => ({
type: FETCH_PLAYERS,
payload: data
})
最后我有减速器:
import { FETCH_PLAYERS } from '../actions/types';
const INITIAL_STATE = {
players: []
}
const playerReducer = (state = INITIAL_STATE, action) => {
console.log(action)
switch (action.type) {
case FETCH_PLAYERS: {
console.log('fetching players?')
return [...state, action.payload]
}
default:
return state
}
}
export default playerReducer;