@restart/hooks
Advanced tools
@@ -7,11 +7,11 @@ /// <reference types="react" /> | ||
| */ | ||
| willHandle(focused: boolean, event: React.FocusEvent): boolean | void; | ||
| willHandle?(focused: boolean, event: React.FocusEvent): boolean | void; | ||
| /** | ||
| * A callback fired after focus is handled but before onChange is called | ||
| */ | ||
| didHandle(focused: boolean, event: React.FocusEvent): void; | ||
| didHandle?(focused: boolean, event: React.FocusEvent): void; | ||
| /** | ||
| * A callback fired after focus has changed | ||
| */ | ||
| onChange(focused: boolean, event: React.FocusEvent): void; | ||
| onChange?(focused: boolean, event: React.FocusEvent): void; | ||
| /** | ||
@@ -18,0 +18,0 @@ * When true, the event handlers will not report focus changes |
+13
-0
@@ -7,3 +7,16 @@ /** | ||
| * @returns a function that returns the current isMounted state of the component | ||
| * | ||
| * ```ts | ||
| * const [data, setData] = useState(null) | ||
| * const isMounted = useMounted() | ||
| * | ||
| * useEffect(() => { | ||
| * fetchdata().then((newData) => { | ||
| * if (isMounted()) { | ||
| * setData(newData); | ||
| * } | ||
| * }) | ||
| * }) | ||
| * ``` | ||
| */ | ||
| export default function useMounted(): () => boolean; |
+17
-3
@@ -14,5 +14,21 @@ "use strict"; | ||
| * @returns a function that returns the current isMounted state of the component | ||
| * | ||
| * ```ts | ||
| * const [data, setData] = useState(null) | ||
| * const isMounted = useMounted() | ||
| * | ||
| * useEffect(() => { | ||
| * fetchdata().then((newData) => { | ||
| * if (isMounted()) { | ||
| * setData(newData); | ||
| * } | ||
| * }) | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function useMounted() { | ||
| var mounted = (0, _react.useRef)(true); | ||
| var isMounted = (0, _react.useRef)(function () { | ||
| return mounted.current; | ||
| }); | ||
| (0, _react.useEffect)(function () { | ||
@@ -23,5 +39,3 @@ return function () { | ||
| }, []); | ||
| return function () { | ||
| return mounted.current; | ||
| }; | ||
| return isMounted.current; | ||
| } |
+1
-1
| { | ||
| "name": "@restart/hooks", | ||
| "version": "0.2.11", | ||
| "version": "0.2.12", | ||
| "main": "index.js", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
@@ -7,11 +7,11 @@ /// <reference types="react" /> | ||
| */ | ||
| willHandle(focused: boolean, event: React.FocusEvent): boolean | void; | ||
| willHandle?(focused: boolean, event: React.FocusEvent): boolean | void; | ||
| /** | ||
| * A callback fired after focus is handled but before onChange is called | ||
| */ | ||
| didHandle(focused: boolean, event: React.FocusEvent): void; | ||
| didHandle?(focused: boolean, event: React.FocusEvent): void; | ||
| /** | ||
| * A callback fired after focus has changed | ||
| */ | ||
| onChange(focused: boolean, event: React.FocusEvent): void; | ||
| onChange?(focused: boolean, event: React.FocusEvent): void; | ||
| /** | ||
@@ -18,0 +18,0 @@ * When true, the event handlers will not report focus changes |
+13
-0
@@ -7,3 +7,16 @@ /** | ||
| * @returns a function that returns the current isMounted state of the component | ||
| * | ||
| * ```ts | ||
| * const [data, setData] = useState(null) | ||
| * const isMounted = useMounted() | ||
| * | ||
| * useEffect(() => { | ||
| * fetchdata().then((newData) => { | ||
| * if (isMounted()) { | ||
| * setData(newData); | ||
| * } | ||
| * }) | ||
| * }) | ||
| * ``` | ||
| */ | ||
| export default function useMounted(): () => boolean; |
+17
-3
@@ -14,5 +14,21 @@ "use strict"; | ||
| * @returns a function that returns the current isMounted state of the component | ||
| * | ||
| * ```ts | ||
| * const [data, setData] = useState(null) | ||
| * const isMounted = useMounted() | ||
| * | ||
| * useEffect(() => { | ||
| * fetchdata().then((newData) => { | ||
| * if (isMounted()) { | ||
| * setData(newData); | ||
| * } | ||
| * }) | ||
| * }) | ||
| * ``` | ||
| */ | ||
| function useMounted() { | ||
| var mounted = (0, _react.useRef)(true); | ||
| var isMounted = (0, _react.useRef)(function () { | ||
| return mounted.current; | ||
| }); | ||
| (0, _react.useEffect)(function () { | ||
@@ -23,5 +39,3 @@ return function () { | ||
| }, []); | ||
| return function () { | ||
| return mounted.current; | ||
| }; | ||
| return isMounted.current; | ||
| } |
67040
1.61%1906
2.92%