Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5288aaaf
Unverified
Commit
5288aaaf
authored
Apr 03, 2019
by
Tim Neutkens
Committed by
GitHub
Apr 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Temporarily pass arguments directly (#6876)
parent
3e7f836c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
data.ts
packages/next/lib/data.ts
+3
-3
No files found.
packages/next/lib/data.ts
View file @
5288aaaf
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment