Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created July 3, 2019 16:04
Show Gist options
  • Save jsmanifest/148512497270cf7797962480d1327278 to your computer and use it in GitHub Desktop.
Save jsmanifest/148512497270cf7797962480d1327278 to your computer and use it in GitHub Desktop.
const SomeComponent = ({ items = [], todaysDate, tomorrowsDate }) => {
const [someState, setSomeState] = useState(null)
return (
<div>
<h2>Today is {todaysDate}</h2>
<small>And tomorrow is {tomorrowsDate}</small>
<hr />
{items.map((item, index) => (
<span key={`item_${index}`}>{item.email}</span>
))}
</div>
)
}
const App = ({ dates, ...otherProps }) => {
let items
if (dates) {
items = dates ? dates.map((d) => new Date(d).toLocaleDateString()) : null
}
return (
<div>
<SomeComponent {...otherProps} items={items} />
</div>
)
}
@chaseholdren
Copy link

I think you made a mistake having the dates ternary inside if(dates)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment