diff --git a/rollup.config.js b/rollup.config.js index 34c5b6f..a7978d8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -20,7 +20,7 @@ export default { ], plugins: [resolve(), typescript(), terser()], external: [ - ...Object.keys(pkg.dependencies), - ...Object.keys(pkg.peerDependencies), + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), ], }; diff --git a/src/context.tsx b/src/context.tsx index 6cecc89..c46fac1 100644 --- a/src/context.tsx +++ b/src/context.tsx @@ -3,15 +3,11 @@ import { BitlyClient } from 'bitly'; import { BitlyConfig } from 'bitly/dist/types'; interface Config { - accessToken: string; - options?: BitlyConfig; + readonly accessToken: string; + readonly options?: BitlyConfig; } -export const ShortenUrlContext = React.createContext<{ - readonly bitly: BitlyClient; -}>({ - bitly: {} as BitlyClient, -}); +export const ShortenUrlContext = React.createContext({} as BitlyClient); ShortenUrlContext.displayName = 'ShortenUrlContext'; @@ -24,8 +20,10 @@ export const ShortenUrlProvider: React.FC<{ readonly config: Config }> = ({ const bitly = new BitlyClient(accessToken, options); return ( - + {children} ); }; + +ShortenUrlProvider.displayName = 'ShortenUrlProvider'; diff --git a/src/useShortenUrl.ts b/src/useShortenUrl.ts index 6301990..71228c7 100644 --- a/src/useShortenUrl.ts +++ b/src/useShortenUrl.ts @@ -9,7 +9,7 @@ export const useShortenUrl = (url: string) => { const [error, setError] = useState(null); const [data, setData] = useState(); - const { bitly } = useSafeContext(ShortenUrlContext); + const bitly = useSafeContext(ShortenUrlContext); useEffect(() => { const shorten = async () => {