t1m0n/air-datepicker

Error when updating 'view' property in React

zaandr opened this issue · 1 comments

Использование:

<InputDatePicker view='months' />

Компонент:

сonst inputRef = useRef<HTMLInputElement>(null);
сonst datepickerRef = useRef<AirDatepicker>();

useEffect(() => {
    if (inputRef.current === null) {
        return;
    }
    datepickerRef.current = new AirDatepicker(inputRef.current, {
        ...props
    });
}, []);

useEffect(() => {
    datepickerRef.current?.update({ ...props });
}, [props]);

Когда datepicker закрыт и React обновляет компонент, где используется datepicker, в update метод приходит каждый раз значения view, и из-за этого происходит ошибка - "cannot read properties 'appendChild'".

setCurrentView = (view) => {
    ...
    if (!this.views[view]) {
         ...
         this.$content.appendChild(newView.$el);   <----- Ошибка, так как это свойство есть только при открытии
    }
}

Посмотрите пожалуйста, или могу предоставить PR как - "проверить на существование":

 this.$content &&  this.$content.appendChild(newView.$el);

Спасибо.

t1m0n commented

@zaandr Спасибо за баг репорт