我正在观看本教程,并且下面的代码在视频中可以正常运行,但是当我尝试它时,出现“未定义派遣”错误。为什么会这样?
import React from 'react'
import {connect} from 'react-redux'
import {removeExpense} from '../actions/actions'
const ListItem = ({id,description,note,amount,createdAt})=>(
<div>
<h5>{description}</h5>
<p>Note: {note}</p>
<p>Amount: {amount}</p>
<p>Created @{createdAt}</p>
<button onClick={()=>{dispatch(removeExpense(id))}}>remove</button>
<br/>
</div>
)
export default connect()(ListItem); //Just to inject dispatch()
讲师正在使用redux v3.7.2,react-redux v5.0.5 react v15。 现在我知道,如果按以下方式进行处理,就可以解决问题。
const ListItem = (props)=>(
<div>
<h5>{props.description}</h5>
<p>Note: {props.note}</p>
<p>Amount: {props.amount}</p>
<p>Created @{props.createdAt}</p>
<button onClick={()=>{props.dispatch(removeExpense(props.id))}}>remove</button>
<br/>
</div>
)
为什么在第一个代码中不能删除按钮?可能是这些库的过时版本吗?