如果選中在智能組件,在容器底部/ App.js你會看到:
// This is where the filtering happens
function selectTodos(todos, filter) {
switch (filter) {
case VisibilityFilters.SHOW_ALL:
return todos
case VisibilityFilters.SHOW_COMPLETED:
return todos.filter(todo => todo.completed)
case VisibilityFilters.SHOW_ACTIVE:
return todos.filter(todo => !todo.completed)
}
}
// Which props do we want to inject, given the global state?
// Note: use https://github.com/faassen/reselect for better performance.
function select(state) {
return {
visibleTodos: selectTodos(state.todos, state.visibilityFilter),
visibilityFilter: state.visibilityFilter
}
}
// Wrap the component to inject dispatch and state into it
export default connect(select)(App)
濾波發生在你連接到將組件發送給商店。 除了在狀態中存儲過濾列表之外,您還可以指定對於此特定組件,您應該過濾從存儲中獲得的待辦事項,然後再將它們作爲道具傳遞給組件。