redux状态如何更新到react组件中?
我尝试使用初始状态而不更改对象并返回
Redux
const initialState = {
filteredProviderData:[],
filteredAlsoSpeaksData:[],
filteredOfficeHours:[]
};
function reducer(state = initialState, action = {}) {
switch (action.type) {
case HANDLE_FILTER_CHANGE:
let filteredProviderData = '';
let filteredAlsoSpeaksData='';
let filteredOfficeHours = ''
return {...state, filteredProviderData,filteredAlsoSpeaksData,filteredOfficeHours};
case RESET_FILTER_COLLECTION:
// RESET the Array as shown into the HANDLE_FILTER_CHANGE
}}
React component
const mapStateToProps = state => {
return {
filteredProviderData:state.providerList && state.providerList.filteredProviderData,
filteredAlsoSpeaksData:state.providerList && state.providerList.filteredAlsoSpeaksData,
filteredOfficeHours:state.providerList && state.providerList.filteredOfficeHours
}}
这里我的问题是如何更新HANDLE_FILTER_CHANGE中的数组
RESET_FILTER_COLLECTION 我需要根据某些条件更新数组并返回更新后的数组
在此条件下,只有一个数组将被更新,并返回只有两个数组保持不变。
答案 0 :(得分:1)
更新Redux存储后,您需要更改本地状态。 this.setState({loading:true})
这种方法会起作用,它也对我有用。