I have app.js as the parent and uploadlist.js as the child. I am passing "userid" which is defined in app.js to uploadlist.js. This is my try:
app.js :
export default class App extends Component {
state = {
userrole : '',
custid : ''
};
componentDidMount() {
if(localStorage.login)
{
const currentuser = JSON.parse(atob(localStorage.login.split(".")[1]));
this.setState( {userrole: currentuser.role });
this.setState( {custid: currentuser.id });
}
}
render() {
if(this.state.userrole === "Customer"){
const userid=this.state.custid;
console.log(userid); //This properly returns the userid in console.
return (
//some code
<Route path="/Uploadlist" render={props => <UploadList userid={props.match.params.userid} />}/>
uploadlist.js:
export default function Uploadlist() {
const userid = this.props.userid;
console.log(userid);
This returns "TypeError: Cannot read property 'props' of undefined" error. How can I solve this?
console.log(props.match.params)in App.js. It returns "props is not defined.