Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when updating 'view' property in React #476

Closed
zaandr opened this issue Jan 27, 2022 · 1 comment
Closed

Error when updating 'view' property in React #476

zaandr opened this issue Jan 27, 2022 · 1 comment
Labels
Milestone

Comments

@zaandr
Copy link

zaandr commented Jan 27, 2022

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

<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
Copy link
Owner

t1m0n commented Jan 31, 2022

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

@t1m0n t1m0n added the bug label Jan 31, 2022
@t1m0n t1m0n added this to the v3.2.0 milestone Feb 17, 2022
@t1m0n t1m0n closed this as completed Mar 27, 2022
pleomax13 pushed a commit to pleomax13/air-datepicker that referenced this issue Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants