I'm trying to navigate between a master detail data format in React. The source page does this:
{myDataList.map(myData =>
<tr key={myData.dataId}>
<td>{myData.dataId}</td>
<td>{myData.dataDescription}</td>
<td>
<NavLink to={'/details/' + myData.dataId}>
Details
</NavLink>
</td>
Clicking the edit link does navigate to the details page with the correct URL; which does this (mainly taken from the example template in VS):
interface DetailsState {
details?: DataDetails;
loading: boolean;
}
export class Details extends React.Component<RouteComponentProps<number>, DetailsState> {
constructor() {
super();
this.state = { details: undefined, loading: true };
console.log("match params: " + this.props.match.params);
fetch('api/Data/Details/' + this.props.match.params)
.then(response => response.json() as Promise<DataDetails>)
.then(data => {
this.setState({ details: data, loading: false });
});
}
My problem is that the console.log like above shows:
TypeError: _this.props is undefined
And so I can't access the dataId
that I'm passing through.
Clearly I'm passing (or receiving) this parameter incorrectly; so my question is: what is the correct way to pass the parameter? It's worth noting that my project is based on the VS Template, and I am using tsx, rather than jsx files.