在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ I have a problem about redux when readin

I have a problem about redux when reading the official document

Hi guys, when I read the document, I have something that I don’t understand.

Please help me.

Question One

I can't understand the function about active: ownProps.filter === state.visibilityFilter

import { connect } from 'react-redux'
import { setVisibilityFilter } from '../actions'
import Link from '../components/Link'

const mapStateToProps = (state, ownProps) => {
  return {
    active: ownProps.filter === state.visibilityFilter
  }
}

const mapDispatchToProps = (dispatch, ownProps) => {
  return {
    onClick: () => {
      dispatch(setVisibilityFilter(ownProps.filter))
    }
  }
}

const FilterLink = connect(
  mapStateToProps,
  mapDispatchToProps
)(Link)

export default FilterLink

Question Two

I don't understand the function about this section

const mapStateToProps = state => {
  return {
    todos: getVisibleTodos(state.todos, state.visibilityFilter)
  }
}

Source Code


import { connect } from 'react-redux'
import { toggleTodo } from '../actions'
import TodoList from '../components/TodoList'

const getVisibleTodos = (todos, filter) => {
  switch (filter) {
    case 'SHOW_COMPLETED':
      return todos.filter(t => t.completed)
    case 'SHOW_ACTIVE':
      return todos.filter(t => !t.completed)
    case 'SHOW_ALL':
    default:
      return todos
  }
}

const mapStateToProps = state => {
  return {
    todos: getVisibleTodos(state.todos, state.visibilityFilter)
  }
}

const mapDispatchToProps = dispatch => {
  return {
    onTodoClick: id => {
      dispatch(toggleTodo(id))
    }
  }
}

const VisibleTodoList = connect(
  mapStateToProps,
  mapDispatchToProps
)(TodoList)

export default VisibleTodoList
回答
編輯回答
終相守
active: ownProps.filter === state.visibilityFilter

這個(gè)需要把整個(gè)return語句連起來看:

return {
    active: ownProps.filter === state.visibilityFilter
}

解釋:意思是返回一個(gè)對象,其active屬性是truefalse,取決于后面的兩個(gè)filter是否相等。

I don't understand the function about this section

具體是什么不明白,箭頭函數(shù)的概念,還是函數(shù)的邏輯?

2018年2月8日 16:56
編輯回答
久愛她

建議你看看ES6和javascript相關(guān)的書籍吧。

2018年7月17日 01:13