I have a multi page web app that uses react-router / react-breadcrumbs (gives you a trail of the pages you've been to.
I'm trying to set up a dynamic breadcrumb passing some data into a method will return the string for the breadcrumb when i navigate to:
http://localhost:9001/compare/templates/2017-06-03&6277
I'm hoping the breadcrumb will look like this:
home > templates > (name of a job)
but instead i get this:
home > templates > Missing name prop from Route
i want the page to wait for the string to be obtained before loading the breadcrumb
as far as i'm aware, this would involve using promise functions, await, async, etc (and as far as i'm aware, i can't return values from promise functions so i need to add the result to the state instead)
for all the console.log lines that were commented out, i can see the data. But the last console.log (in getTemplateJobName() ), i get an error because jobName
Uncaught TypeError: Cannot read property 'jobName' of null
I've been stuck on this for a long time, and it's been aggravating me quite badly, can anyone please advise? :'(
setStateAsync(state) {
return new Promise((resolve) => {
this.setState(state, resolve);
// console.log(this.state.jobName);
});
},
getTemplateJobName(templateId,dateChosen){ //getTemplateJobName(job){ //
const makeRequest = async () => {
try {
const data = await doGetJobById({jobId: templateId,reconDate: dateChosen});
// console.log(data)
await this.setStateAsync({jobName: data});
// this.setState({jobName: data});
} catch (err) {
console.log(err)
}
};
console.log(this.state.jobName);
//return this.state.jobName.jobName (this is the end result i want, to return the state to the route component used below)
render(){
return (
<div>
<Router history={browserHistory}>
<Route name='home' path={'/'+contextName}>
<IndexRoute component={LandingPage}/>
<Route name='templates' path='templates'>
<IndexRoute component={JobPage}/>
<Route path=':reconDate&:templateId' component={JobDetailPage} staticName={true} getDisplayName={(params)=> (this.getTemplateJobName(params.templateId,params.reconDate))}/>
</Route>
<Route name='report' path='report' component={ReportPanel}/>
</Route>
<Route path='*' component={NotFoundPage}/>
</Router>
<ModalManager/>
<NotificationSystem ref='notificationSystem'/>
<ReactTooltip ref='reactTooltip' place='top' type='dark' effect='solid' />
</div>
)
}
});