From 87e86f4c4b85258fa717a942674536afc392d7f3 Mon Sep 17 00:00:00 2001 From: Rico Kahler Date: Mon, 7 Dec 2020 02:37:24 -0500 Subject: [PATCH 1/2] remove Unwrap; function must always return a promise --- src/create-data-hook.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/create-data-hook.ts b/src/create-data-hook.ts index ce73bf98..734c83fe 100644 --- a/src/create-data-hook.ts +++ b/src/create-data-hook.ts @@ -2,8 +2,6 @@ import { useContext } from 'react'; import { GetStaticPropsContext } from 'next'; import NextDataHooksContext from './next-data-hooks-context'; -type Unwrap = T extends Promise ? U : T; - const stub = () => { throw new Error( 'Create data hook was run in the browser. See https://github.com/ricokahler/next-data-hooks#code-elimination' @@ -19,9 +17,9 @@ const stub = () => { */ function createDataHook( key: string, - getData: (variables: GetStaticPropsContext) => R | Promise + getData: (variables: GetStaticPropsContext) => Promise ) { - function useData(): Unwrap { + function useData(): R { const dataHooksContext = useContext(NextDataHooksContext); if (!dataHooksContext) { throw new Error( From 2152d620314331e0d91b921c232f2b9ca2cc3ff7 Mon Sep 17 00:00:00 2001 From: Rico Kahler Date: Mon, 7 Dec 2020 02:37:46 -0500 Subject: [PATCH 2/2] bump --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5f24a55e..136163eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "next-data-hooks", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9a1f79b5..d2ea1775 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-data-hooks", - "version": "0.2.0", + "version": "0.2.1", "description": "Use `getStaticProps` as react hooks", "private": true, "scripts": {