@restart/hooks
Advanced tools
Comparing version 0.2.11 to 0.2.12
@@ -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 |
@@ -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; |
@@ -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; | ||
} |
{ | ||
"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 |
@@ -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; |
@@ -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; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67040
1906