Unverified Commit 5288aaaf authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Temporarily pass arguments directly (#6876)

parent 3e7f836c
...@@ -3,11 +3,11 @@ import { DataManagerContext } from 'next-server/dist/lib/data-manager-context' ...@@ -3,11 +3,11 @@ import { DataManagerContext } from 'next-server/dist/lib/data-manager-context'
import { RouterContext } from 'next-server/dist/lib/router-context' import { RouterContext } from 'next-server/dist/lib/router-context'
import fetch from 'unfetch' import fetch from 'unfetch'
export function createHook(fetcher: () => Promise<any>, options: {key: string}) { export function createHook(fetcher: (...args: any) => Promise<any>, options: {key: string}) {
if (!options.key) { if (!options.key) {
throw new Error('key not provided to createHook options.') throw new Error('key not provided to createHook options.')
} }
return function useData() { return function useData(...args: any) {
const router: import('next-server/lib/router/router').default = useContext(RouterContext) const router: import('next-server/lib/router/router').default = useContext(RouterContext)
const dataManager: import('next-server/lib/data-manager').DataManager = useContext(DataManagerContext) const dataManager: import('next-server/lib/data-manager').DataManager = useContext(DataManagerContext)
const existing = dataManager.get(options.key) const existing = dataManager.get(options.key)
...@@ -22,7 +22,7 @@ export function createHook(fetcher: () => Promise<any>, options: {key: string}) ...@@ -22,7 +22,7 @@ export function createHook(fetcher: () => Promise<any>, options: {key: string})
}) })
throw res throw res
} else { } else {
const res = fetcher().then((result) => { const res = fetcher(...args).then((result) => {
dataManager.set(options.key, { dataManager.set(options.key, {
status: 'resolved', status: 'resolved',
result, result,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment