Jesus sucks
This commit is contained in:
36
backend/frontend/node_modules/@restart/hooks/cjs/useMounted.js
generated
vendored
Normal file
36
backend/frontend/node_modules/@restart/hooks/cjs/useMounted.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
exports.default = useMounted;
|
||||
var _react = require("react");
|
||||
/**
|
||||
* Track whether a component is current mounted. Generally less preferable than
|
||||
* properlly canceling effects so they don't run after a component is unmounted,
|
||||
* but helpful in cases where that isn't feasible, such as a `Promise` resolution.
|
||||
*
|
||||
* @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() {
|
||||
const mounted = (0, _react.useRef)(true);
|
||||
const isMounted = (0, _react.useRef)(() => mounted.current);
|
||||
(0, _react.useEffect)(() => {
|
||||
mounted.current = true;
|
||||
return () => {
|
||||
mounted.current = false;
|
||||
};
|
||||
}, []);
|
||||
return isMounted.current;
|
||||
}
|
||||
Reference in New Issue
Block a user