Skip to content

Commit

Permalink
typing fix for hook args
Browse files Browse the repository at this point in the history
  • Loading branch information
onderonur committed Oct 15, 2022
1 parent 4165e98 commit 60a3ac5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 23 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ module.exports = {
},
},
},
// https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/TROUBLESHOOTING.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
overrides: [
{
files: ['*.ts', '*.mts', '*.cts', '*.tsx'],
rules: {
'no-undef': 'off',
},
},
],
rules: {
'prettier/prettier': 'warn',
'no-shadow': 'warn',
Expand Down
137 changes: 118 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-intersection-observer-hook",
"version": "2.0.4",
"version": "2.0.5",
"license": "MIT",
"author": "onderonur",
"main": "dist/index.js",
Expand Down Expand Up @@ -46,6 +46,7 @@
"eslint": "^7.23.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^7.2.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
9 changes: 6 additions & 3 deletions src/useIntersectionObserver.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { useState, useCallback, useEffect, useRef } from 'react';
import { Omit } from './types';

const DEFAULT_ROOT_MARGIN = '0px';
const DEFAULT_THRESHOLD = [0];

// eslint-disable-next-line no-undef
export type IntersectionObserverHookArgs = IntersectionObserverInit;
export type IntersectionObserverHookArgs = Omit<
IntersectionObserverInit,
'root'
>;

export type IntersectionObserverHookRefCallbackNode = Element | null;

export type IntersectionObserverHookRefCallback = (
node: IntersectionObserverHookRefCallbackNode,
) => void;

export type IntersectionObserverHookRootRefCallbackNode = IntersectionObserverHookArgs['root'];
export type IntersectionObserverHookRootRefCallbackNode = IntersectionObserverInit['root'];

export type IntersectionObserverHookRootRefCallback = (
node: IntersectionObserverHookRootRefCallbackNode,
Expand Down

0 comments on commit 60a3ac5

Please sign in to comment.