StephenChou1017 / react-big-scheduler

A scheduler and resource planning component built for React and made for modern browsers (IE10+)
https://stephenchou1017.github.io/scheduler/#/
MIT License
760 stars 414 forks source link

How to set events and resources from api? #219

Open nikolara opened 4 years ago

nikolara commented 4 years ago

I am unable to find a way to make this happen, tried to setState with componentDidMount, componentWillMount, event tried to re-render the component when the state is set, and nothing works. Does someone have a solution for this maybe?

KitanoR commented 4 years ago

hi! i set my data from api in componentDidUpdate. I compare the prevProps with props. If the data is changed i set resourses and events. the next code is my implementation

componentDidUpdate(prevProps) {
        const { dataSchedule } = this.props;
        if (prevProps.dataSchedule !== dataSchedule) {
            this.setState({ viewModel: null });
            const today = moment().format(DATE_FORMAT);
            const schedulerData = new SchedulerData(today, ViewTypes.Week, false, false, configuracion);

            schedulerData.localeMoment.locale();
            schedulerData.setResources(dataSchedule.instructores);
            schedulerData.setEvents(dataSchedule.actividades);
            schedulerData.documentWidth = this.props.width;
            this.setState({
                viewModel: schedulerData,
            });
        }
    }