import {
SEARCH_CHAT_FROM_RECENT_CHAT_CONTAT_LIST,
GET_RECENT_CHAT_CONTAT_LIST_REQUEST,
GET_RECENT_CHAT_CONTAT_LIST_SUCCESS,
GET_RECENT_CHAT_CONTAT_LIST_FAILURE
} from "../actions/action-types";
const INTIAL_STATE = {
response: null,
error: null,
loading: false,
searchResults: null,
};
searchChatFromRecentChatContactList = (state, text) => {
if(state.response && state.response.length > 0) {
const response = [...state.response];
const searchResults = response.filter(item => item.displayName.includes(text));
return searchResults;
}
return [];
}
export default (state = INTIAL_STATE, action) => {
switch (action.type) {
case GET_RECENT_CHAT_CONTAT_LIST_REQUEST:
return { ...state, loading: true, response: null, error: null, };
case GET_RECENT_CHAT_CONTAT_LIST_SUCCESS:
return { ...state, response: action.payload, loading: false};
case GET_RECENT_CHAT_CONTAT_LIST_FAILURE:
return { ...state, response: null, error: action.payload, loading: false };
case SEARCH_CHAT_FROM_RECENT_CHAT_CONTAT_LIST:
return {...state, searchResults: searchChatFromRecentChatContactList(state, action.payload)};
default:
return state;
}
};
내 state.response
이 아니라 내 아래의 방법은 항상 [] 반환 어떤 이유로 문자열의 배열을 가지고;Array.prototype.filter()는 출력을 예상 제공되지
state.response = [{displayName: 'someText'}, {displayName: 'someText otherText'];
입력 :
searchChatFromRecentChatContactList(state, 'SomeText')
출력 :
[];
새로 만든 때문에 Array.prototype.filter의 특성 여기 반환 필요한 당신이 전달하는 텍스트의 값을 확인하지 않습니다 searchChatFromRecentChatContactList 함수 – stack26
감사합니다 @ stack26 :-) –