I am trying to send props to another component when the Link to is used.
const printArr = sameLetterArr.map((obj, idx) => {
return (
<Link to={{ pathname: '/coursePage', state: { linkState: 'hello' } }} key={idx}>
<li className={'DeptList'}>
{obj.CRS_SUBJ_CD} - {obj.DEPT_NAME}
</li>
</Link>
)
})
This is the Link to that I am trying to use, and I am sending in linkState
that has a string of hello. To receive it I have tried this.props.location.state
and this.props.history.location.state
but they both result in error:
TypeError: undefined is not an object (evaluating 'this.props.history.location').
Not sure what can be causing this. Any insight would be great.
EDIT: the CoursePage
component below:
render () {
console.log(this.props.location.linkState)
return (
<div className='App'>
<header className="Header"></header>
<div>
<h1>Dept</h1>
<p><ListCourse letter={this.props.title}/></p>
</div>
<footer className="Footer">This is the footer</footer>
</div>
)
};