Custom content in CalendarDay with #renderDay#307
Custom content in CalendarDay with #renderDay#307majapw merged 1 commit intoreact-dates:masterfrom relayrides:issue-127_renderDay
Conversation
|
|
||
| if (renderDay) { | ||
| const result = renderDay(day); | ||
| return typeof result === 'string' ? result : Children.only(result); |
There was a problem hiding this comment.
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.
majapw
left a comment
There was a problem hiding this comment.
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!
| onClick={e => this.onDayClick(day, e)} | ||
| > | ||
| {day.format('D')} | ||
| {this.renderDay(day)} |
There was a problem hiding this comment.
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.
@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.
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: |
| onClick={e => this.onDayClick(day, e)} | ||
| > | ||
| {day.format('D')} | ||
| {renderDay ? renderDay(day) : day.format('D')} |
There was a problem hiding this comment.
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.
@Bamieh we already discussed that here: #307 (review)
Replaces #283