0

I'm Very new to react and I have a conditional statement in react in a table cell and when user are in the the Search nav it shows the birthdate that's coming up fine however getting errors when I simply like to mix in text element the word "birthday" beside the date.

the string below:

cell: (row) => (
                <>
                    <div class="dob">{`${row.firstName} ${row.lastName} ${
                        history.location.pathname.toLowerCase().includes('search') && row.maidenName ? `(${row.maidenName})` : ''
                    }
                    
                  `}</div>
                    <div>{`${history.location.pathname.toLowerCase().includes('search') && row.birthdate ? formatDate(new Date(row.birthdate)) : ''}
                  `}</div>
                </>
            ),

1 Answer 1

1

I don't know if this is what you wanted to do, but here's how I would display the word "Birthday" besides the date:

cell: (row) => {
let maidenName = (history.location.pathname.toLowerCase().includes('search') && row.maidenName) ? row.maidenName : '';
let birthdate = (history.location.pathname.toLowerCase().includes('search') && row.birthdate) ? formatDate(new Date(row.birthdate)) : '';

return <>
        <div class="dob">{`${row.firstName} ${row.lastName} ${maidenName}`}</div>
        <div>{`Birthday: ${birthdate}`}</div>
</>

}

Sign up to request clarification or add additional context in comments.

2 Comments

It worked thanks however just some formatting I have to work out as I didnd fully demonstrate what I was trying to accomplish however the method you helped me look at the problem as I should; .formatting the date first then passing it to the div so that could place text into it. . My app the birthdate and date should only show on the search page grid as the the other pages share the same grid. and the word birthday is showing up on the other pages as the date is only showing as it should on search page grid..
This line is complaining changed it though to: let birthdate = (formatDate(new Date(row.birthdate)); ....missing a coma ?? as I think I need to have the history line etc in the div birthday as line as you had outlined as Im getting the word birthday great however on the other pages too. only like to have it in the shared search grid cell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.