I'm trying to pass props from one component into a Class component via a <Link> using React-Router.... But I'm having trouble...
I have this code in one component wrapping text/image:
<Link to={{ pathname: "/newPage", state: {userName: uName, userGender: uGen}}}>
<img src={newIcon}> Link text goes here</img>
</Link>
(uName & uGen are consts which are generated in code above)
and in my Class page I have:
class NewPage extends React.Component<Props, State> {
constructor(props: any) {
this.state = {
userName: '',
userGender: '',
}
}
render() {
return (
...Content goes here...
{userName} & {userGender}
)
}
}
export default NewPage
This renders the new page, but for the life of me I can't access the props I'm trying to pass into it. Can anyone point me in the right direction as to what I'm doing wrong? I'm very new to this...
Thanks in advance for any pointers :)