Please make our job easier by filling this template out to completion. If you're requesting a feature instead of reporting a bug, please feel free to skip the Environment and Reproducible Demo sections.
1-2 sentences describing the problem you're having or the feature you'd like to request
What action did you perform, and what did you expect to happen?
What actually happened when you performed the above actions?
If there's an error message, please paste the full terminal output and error message in this code block:
Error text goes here!
Please run these commands in the project folder and fill in their results:
npm ls react-native-calendars:npm ls react-native:Also specify:
Please provide a minimized reproducible demonstration of the problem you're reporting.
Issues that come with minimal repro's are resolved much more quickly than issues where a maintainer has to reproduce themselves.
+1 Same problem here
All my agenda items are stored in the current state of my component. When I update the state using
this.setState({ items: newItems }) the agenda does not re-render.
When the new state is set, the whole agenda component should re-render and display my new/changed items.
Nothing happens. The agenda does not re-render. Even when I force it with this.forceUpdate()
```
// I want to update my agenda when the component
// receives new props from the parent component
componentWillReceiveProps(nextProps, oldProps) {
if (nextProps.getEvents && this._day && nextProps.getEvents !== oldProps.getEvents) {
this.loadItemsForMonth(this.selectedDay);
}
}
// Create a list of days for the current month (+- 1 month)
loadItemsForMonth = (day) => {
const items = {};
this.selectedDay = day;
const month = moment(${day.year}-${day.month - 1}-01, 'YYYY-MM-DD');
for (let j = 0; j <= 93; j += 1) {
items[${month.format('YYYY-MM-DD')}] = [];
month.add(1, 'days');
}
const events = this.props.getEvents();
Object.keys(events).forEach((key) => {
items[key] = events[key];
});
this.setState({ items });
};
render() {
return (
loadItemsForMonth={day => this.loadItemsForMonth(day)}
renderItem={this.renderItem.bind(this)}
renderEmptyDate={this.renderEmptyDate.bind(this)}
rowHasChanged={this.rowHasChanged.bind(this)}
firstDay={1}
theme={theme}
/>
);
Hi. You would to try update it like this
<Agenda
items={JSON.parse(JSON.stringify(this.state.items))}
loadItemsForMonth={this._loadItems}
renderItem={this._renderItem}
renderEmptyDate={this._renderEmptyDate}
rowHasChanged={this._rowHasChanged}
/>
I found my problem. The reason my agenda didn't update was the _rowHasChanged function.
_rowHasChanged = (r1, r2) => r1.id !== r2.id;
==>
_rowHasChanged = (r1, r2) => r1 !== r2;
I didn't realise what the function was doing. I thought it would be necessary for the list view in my agenda to keep track when I'm scrolling. But it when I update my items, eg. change the title of an event, the IDs are still the same and the agenda thinks nothing has changed.
I got this working using redux. I have a Reset to initial state reducer:
case RESET_AGENDA:
return {
...initialState,
};
P.s. This solution only works if you're using redux.
Most helpful comment
I found my problem. The reason my agenda didn't update was the
_rowHasChangedfunction._rowHasChanged = (r1, r2) => r1.id !== r2.id;==>
_rowHasChanged = (r1, r2) => r1 !== r2;I didn't realise what the function was doing. I thought it would be necessary for the list view in my agenda to keep track when I'm scrolling. But it when I update my items, eg. change the title of an event, the IDs are still the same and the agenda thinks nothing has changed.