Skip to content

Commit

Permalink
Merge pull request #8 from ricokahler/fix/types
Browse files Browse the repository at this point in the history
fix: types
  • Loading branch information
ricokahler authored Dec 7, 2020
2 parents 376fcd9 + 2152d62 commit 0a1345b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 2 additions & 4 deletions src/create-data-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { useContext } from 'react';
import { GetStaticPropsContext } from 'next';
import NextDataHooksContext from './next-data-hooks-context';

type Unwrap<T> = T extends Promise<infer U> ? 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'
Expand All @@ -19,9 +17,9 @@ const stub = () => {
*/
function createDataHook<R>(
key: string,
getData: (variables: GetStaticPropsContext) => R | Promise<R>
getData: (variables: GetStaticPropsContext) => Promise<R>
) {
function useData(): Unwrap<R> {
function useData(): R {
const dataHooksContext = useContext(NextDataHooksContext);
if (!dataHooksContext) {
throw new Error(
Expand Down

0 comments on commit 0a1345b

Please sign in to comment.