mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Review feedback: avoid swallowing errors
This commit is contained in:
parent
6f68437359
commit
2cf2ab00eb
22
src/util.ts
22
src/util.ts
@ -1,23 +1,5 @@
|
||||
export const isClient = typeof window === 'object';
|
||||
|
||||
export const on = (obj: any, ...args: any[]) => {
|
||||
try {
|
||||
obj.addEventListener(...args);
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
}
|
||||
};
|
||||
export const on = (obj: any, ...args: any[]) => obj && obj.addEventListener(...args);
|
||||
|
||||
export const off = (obj: any, ...args: any[]) => {
|
||||
try {
|
||||
obj.removeEventListener(...args);
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleError = (error: any) => {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
export const off = (obj: any, ...args: any[]) => obj && obj.removeEventListener(...args);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user