I have a react component. If I user clicks on a Link To on the parent component they land on this child componented just fine. However if they refresh the page, or go to the link directly, their is no data, so I need to make an api call again myself for that unique id.
When I make the api call (when issue is undefined), it works, but I get a promise back that has fulfilled, with no data. How do I get the object?
class Issue extends React.Component {
getIssue = async (id) => {
try {
const endpoint = `https://api.github.com/repos/facebook/create-react-app/issues/${id}`;
const response = await fetch(endpoint);
const data = await response.json();
return data;
} catch (error) {
console.log(error);
}
}
// }
render(){
let { issue } = this.props.location;
console.log(issue);
if(issue === undefined){
console.log('No Data');
issue = this.getIssue(this.props.match.params.id);
console.log(issue);
} else {
console.log('Data');
}
return (
<h1>ff</h1>
)
}
}