[Redux Component - Agenda] renderItem() is not called when props are updated
Hi,
I'm following the best practices from Presentational and Container Components: I wrap Agenda in a stateless component, contained by a Redux stateful container. I pass items data via the props
- Rendering works well with Redux initial state (
itemsarray empty) - Rendering works well after update with the
itemsdata from Redux action => API - Rendering of the items does'nt work after another update from another action (update of an item in a modal view)
I investigated 3 :
- Props updates are correctly propagated to
Agenda - Items are updated. I can track it because I transform the input data before passing them as arguments
- renderItem() is not called
- renderItem() is called and renders the updated values when I scrolled up/down the calendar
=> Is there anything I miss? Or is there a way to trigger renderItem()?
Thanks
For info, here is my Agenda component:
const ScheduleAgenda = ({ schedule = { }, toggleEventModal = null }) => {
const { afterDate, beforeDate } = schedule
return (
<Agenda
items={eventToAgendaItem(schedule)}
// loadItemsForMonth={(month) => { console.log('trigger items loading') }}
// onCalendarToggled={(calendarOpened) => { console.log(calendarOpened) }}
// onDayPress={day => onDayPress(day, schedule)}
// onDayChange={(day) => { console.log('day changed') }}
selected={moment.utc().format('YYYY-MM-DD')}
minDate={afterDate}
maxDate={beforeDate}
pastScrollRange={PAST_SCROLL_RANGE}
futureScrollRange={FUTURE_SCROLL_RANGE}
renderItem={(item, firstItemInDay) => renderItem(item, firstItemInDay, toggleEventModal)}
// renderDay={renderDay}
renderEmptyDate={renderEmptyDate}
renderKnob={renderKnob}
renderEmptyData={() => { return (<View />) }}
rowHasChanged={(r1, r2) => { return r1.text !== r2.text }}
hideKnob={false}
theme={theme}
// style={{}}
/>
)
}
Problem solved: my function rowHasChanged was not doing the right job, so the items were not rendered again.
Comment about the clarity of the function / documentation: why use the word row when the actual compared data are items? Maybe if the function were called itemHasChanged, the cause of the problem would have bumped earlier to me.
Anyway, thanks for this great component!
@matieux How did you solve it? I'm having the same issue
Hi @vitoravale rowHasChanged is used to compare the before / after item component and trigger a new rendering or not => You must adapt the default function to your own item attributes
Just wanted to thank you @matieux. Was tearing my hair out trying to figure this one out. And I agree, the rowHasChanged naming doesn't make a whole lot of sense.