Gazebo_simulation-Frontend/node_modules/.cache/babel-loader/159a3b5ee174d7480b6d98dca41...

1 line
987 B
JSON

{"ast":null,"code":"import { useRef, useEffect } from 'react';\n/**\n * Track whether a component is current mounted. Generally less preferable than\n * properlly canceling effects so they don't run after a component is unmounted,\n * but helpful in cases where that isn't feasible, such as a `Promise` resolution.\n *\n * @returns a function that returns the current isMounted state of the component\n *\n * ```ts\n * const [data, setData] = useState(null)\n * const isMounted = useMounted()\n *\n * useEffect(() => {\n * fetchdata().then((newData) => {\n * if (isMounted()) {\n * setData(newData);\n * }\n * })\n * })\n * ```\n */\n\nexport default function useMounted() {\n var mounted = useRef(true);\n var isMounted = useRef(function () {\n return mounted.current;\n });\n useEffect(function () {\n return function () {\n mounted.current = false;\n };\n }, []);\n return isMounted.current;\n}","map":null,"metadata":{},"sourceType":"module"}