亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 2 個反應組件中使用相同的功能。第二個不起作用

在 2 個反應組件中使用相同的功能。第二個不起作用

回首憶惘然 2022-06-09 11:09:46
我與 TypeError 斗爭:deleteEducation 不是一個函數 - 2 個 React 組件中的相同函數。該組件有效。    import React, { Fragment } from 'react'    import PropTypes from 'prop-types';    import { connect } from 'react-redux';    import Moment from 'react-moment';    import { deleteEducation } from '../../actions/profile';    export const Education = ({ education, deleteEducation }) => {        const educations = education.map(edc => (            <tr key={edc._id}>                <td>                    <button className='btn btn-danger' onClick={() => deleteEducation(edc._id)} >Delete</button>                </td>            </tr>        ));        return (            <Fragment>                <h2 className='my-2'>Education Credentials</h2>                <table className="table">                    <tbody>                        {educations}                    </tbody>                </table>            </Fragment>        )    }    Education.propTypes = {        education: PropTypes.array.isRequired,        deleteEducation: PropTypes.func.isRequired,    }    export default connect(null, { deleteEducation })(Education);這沒有。我想使用另一種不同的方法來刪除Experience()。它不起作用,所以我嘗試了相同的功能,但組件名稱不同。import React, { Fragment } from 'react'import PropTypes from 'prop-types';import { connect } from 'react-redux';import Moment from 'react-moment';import { deleteEducation } from '../../actions/profile';export const Experience = ({ education, deleteEducation }) => {    const educations = education.map(edc => (        <tr key={edc._id}>            <td>                <button className='btn btn-danger' onClick={() => deleteEducation(edc._id)} >Delete</button>            </td>            </tr>    ));    return (            <Fragment>                <h2 className='my-2'>Education Credentials</h2>                <table className="table">                    <tbody>                        {educations}                    </tbody>                </table>            </Fragment>    )}
查看完整描述

2 回答

?
拉丁的傳說

TA貢獻1789條經驗 獲得超8個贊

您需要在兩個組件的連接包裝器中使用參數分派您的函數。


改變


export default connect(null, { deleteEducation })(Experience);


const mapDispatchToProps = dispatch => ({

  deleteEducation: id => dispatch(deleteEducation(id))

})

export default connect(null, mapDispatchToProps)(Experience);


查看完整回答
反對 回復 2022-06-09
?
烙印99

TA貢獻1829條經驗 獲得超13個贊

我的導入錯誤,未包含在我的帖子中。抱歉 React 自動添加了默認導入,我沒有注意到。

import { Experience }  from './Experience';
import Education from './Education';


查看完整回答
反對 回復 2022-06-09
  • 2 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號