Skip to content

Instantly share code, notes, and snippets.

@nesbtesh
Last active July 25, 2022 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nesbtesh/5a1b21d4f3c36db578d57aa04ed60144 to your computer and use it in GitHub Desktop.
Save nesbtesh/5a1b21d4f3c36db578d57aa04ed60144 to your computer and use it in GitHub Desktop.
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