我與 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 個反應組件中使用相同的功能。第二個不起作用
回首憶惘然
2022-06-09 11:09:46