javascript - Jsx concatenation using template literal string in filter and map -


what should correct below code?

<p> {ads.filter(obj => obj._id === this.state.selectedad_id) .map(obj =>obj.expiry_date &&  `you have complete task in${fromnow(moment(obj.expiry_date))}` )} </p> 

this working

<p> {ads.filter(obj => obj._id === this.state.selectedad_id) .map(obj => obj.expiry_date && fromnow(moment(obj.expiry_date)) )} </p> 

but how can concat you have complete task in when obj.expiry_date not null?

you can return ternary , use template literal string interpolation es6.

ads.filter(obj => obj._id === this.state.selectedad_id)    .map(obj => obj.expiry_date ? `you have complete task in ${fromnow(moment(obj.expiry_date))}` : false) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -