Skip to content

Commit

Permalink
fix: Fix useClickOutside ref ts type
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGhost23 committed Mar 15, 2024
1 parent e087645 commit 190daa2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
7 changes: 5 additions & 2 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RefObject, DependencyList } from 'react';
import { DependencyList } from 'react';
import { AxiosRequestConfig } from 'axios';

type RequestConfig = {
Expand All @@ -15,7 +15,10 @@ declare const useFetch: () => {
};

type ClickOutsideCallback = () => void;
declare const useClickOutside: (callbackFun: ClickOutsideCallback) => RefObject<HTMLElement | null>;
type SafeRefObject<T> = {
readonly current: T;
};
declare const useClickOutside: <T extends HTMLElement>(callbackFun: ClickOutsideCallback) => SafeRefObject<T>;

type EffectFunction = () => void;
declare const useEffectExceptFirstRender: (func: EffectFunction, deps: DependencyList) => void;
Expand Down
7 changes: 5 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RefObject, DependencyList } from 'react';
import { DependencyList } from 'react';
import { AxiosRequestConfig } from 'axios';

type RequestConfig = {
Expand All @@ -15,7 +15,10 @@ declare const useFetch: () => {
};

type ClickOutsideCallback = () => void;
declare const useClickOutside: (callbackFun: ClickOutsideCallback) => RefObject<HTMLElement | null>;
type SafeRefObject<T> = {
readonly current: T;
};
declare const useClickOutside: <T extends HTMLElement>(callbackFun: ClickOutsideCallback) => SafeRefObject<T>;

type EffectFunction = () => void;
declare const useEffectExceptFirstRender: (func: EffectFunction, deps: DependencyList) => void;
Expand Down
27 changes: 19 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hookverse",
"version": "1.4.0",
"version": "1.4.1",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useClickOutside.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useEffect, useRef, RefObject } from "react";
import { useEffect, useRef } from "react";

type ClickOutsideCallback = () => void;
type SafeRefObject<T> = { readonly current: T };

const useClickOutside = (
const useClickOutside = <T extends HTMLElement>(
callbackFun: ClickOutsideCallback
): RefObject<HTMLElement | null> => {
const elementRef = useRef<HTMLElement | null>(null);
): SafeRefObject<T> => {
const elementRef = useRef<T>(HTMLElement as unknown as T);
const callBackFunRef = useRef<ClickOutsideCallback | null>(null);
callBackFunRef.current = callbackFun;

Expand Down

0 comments on commit 190daa2

Please sign in to comment.