-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom content in CalendarDay with #renderDay #307
Conversation
src/components/CalendarDay.jsx
Outdated
|
||
if (renderDay) { | ||
const result = renderDay(day); | ||
return typeof result === 'string' ? result : Children.only(result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, after more exploration, we kind of realized that we should probably just return the result directly because Children.only
breaks on null
, string
, number
, undefined
... etc. X_x I thought this function did something slightly different then it does.
Basically we should just have {renderDay ? renderDay(day) : day.format('D')}directly in the
` instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one comment, unfortunately, backtracking on our previous recommendation and then this is ready to go.
If you can squash your commits into just one, that would also be appreciated. Thank you!
src/components/CalendarDay.jsx
Outdated
@@ -64,7 +76,7 @@ export default class CalendarDay extends React.Component { | |||
onMouseLeave={e => this.onDayMouseLeave(day, e)} | |||
onClick={e => this.onDayClick(day, e)} | |||
> | |||
{day.format('D')} | |||
{this.renderDay(day)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alternative would be to get rid of the instance method entirely, and just define the defaultProp value for renderDay
to be day => day.format('D')
, and do {renderDay(day)}
inline here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb the linter requires that we have default props at every level, so we would have to use renderDay: undefined
instead of null
in the wrapping components, and it seems like that pattern is discouraged. I think the instance method (or the ternary directly in render) is easier to reason about given that requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, altho defaulting to undefined elsewhere would be fine too.
@majapw updated, rebased, and squashed |
@evandavis I'm trying this out and returning the day, then some content in a span. Works pretty decently but the span gets rendered as plaintext (<, etc). Not sure if this is intentional but once again just throwing in my two cents! |
@zachfeldman can you post your |
@evandavis you're right :). Fixed it to a React node and now we're good! Thanks! |
@zachfeldman 👍 return an array if you need adjacent nodes: |
@@ -64,7 +67,7 @@ export default class CalendarDay extends React.Component { | |||
onMouseLeave={e => this.onDayMouseLeave(day, e)} | |||
onClick={e => this.onDayClick(day, e)} | |||
> | |||
{day.format('D')} | |||
{renderDay ? renderDay(day) : day.format('D')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to have the default renderDay function as (day) => day.format('D')
and just call it always, no need for the if statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bamieh we already discussed that here: #307 (review)
Replaces #283