Last active
July 25, 2022 00:05
-
-
Save nesbtesh/5a1b21d4f3c36db578d57aa04ed60144 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext, createContext, useState, useRef } from "react"; | |
import { useParams } from "react-router-dom"; | |
import useBluelagoon from "../bluelagon/hooks/useBluelagoon"; | |
const SomethingContext = createContext(); | |
function useProvideSomething() { | |
const { id } = useParams(); | |
const { wrappedApi, isLoading, error, response } = useBluelagoon({ | |
method: "getSomethingData", | |
}); | |
const handleFetchData = React.useCallback(() => { | |
wrappedApi({ | |
_id: id, | |
}); | |
}, [wrappedApi, id]); | |
React.useEffect(() => { | |
handleFetchData(); | |
}, [id]); | |
return { | |
refetch: handleFetchData, | |
isLoading, | |
error, | |
response, | |
id, | |
}; | |
} | |
export function useSomething() { | |
return useContext(SomethingContext); | |
} | |
export function ProvideSomething({ children }) { | |
const fact = useProvideSomething(); | |
return ( | |
<SomethingContext.Provider value={fact}> | |
{children} | |
</SomethingContext.Provider> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment