Fix null reference TypeScript errors - ref.current

This commit is contained in:
Dmitry Lyzo 2022-02-16 00:37:06 +03:00
parent 4952fc0119
commit 109fe6056a
5 changed files with 241 additions and 108 deletions

View file

@ -34,6 +34,13 @@ const UserProfilesPage: FunctionComponent = () => {
};
useEffect(() => {
const page = element.current;
if (!page) {
console.error('Unexpected null reference');
return;
}
loadData();
const showUserMenu = (elem: HTMLElement) => {
@ -105,7 +112,7 @@ const UserProfilesPage: FunctionComponent = () => {
});
};
element?.current?.addEventListener('click', function (e) {
page.addEventListener('click', function (e) {
const btnUserMenu = dom.parentWithClass(e.target, 'btnUserMenu');
if (btnUserMenu) {
@ -113,7 +120,7 @@ const UserProfilesPage: FunctionComponent = () => {
}
});
element?.current?.querySelector('.btnAddUser').addEventListener('click', function() {
page.querySelector('.btnAddUser').addEventListener('click', function() {
Dashboard.navigate('usernew.html');
});
}, []);