Skip to content

Commit 4b1018a

Browse files
authored
Merge pull request #22 from third774/fix-types-in-react-example
Fix types in React example
2 parents 3c499a1 + e3062cf commit 4b1018a

File tree

1 file changed

+6
-5
lines changed
  • examples/worker-react/web/src/main

1 file changed

+6
-5
lines changed

examples/worker-react/web/src/main/App.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React, { useMemo, useState } from 'react'
1+
import { useMemo, useState } from 'react'
22
import { newHttpBatchRpcSession } from '@cloudflare/jsrpc'
3+
import type { Api } from '../../../src/worker'
34

45
type Result = {
56
posts: number
@@ -55,7 +56,7 @@ export function App() {
5556
const t0 = performance.now()
5657
wrapFetch.setOrigin(t0)
5758
const calls: CallEvent[] = []
58-
const api = newHttpBatchRpcSession('/api')
59+
const api = newHttpBatchRpcSession<Api>('/api')
5960
const userStart = 0; calls.push({ label: 'authenticate', start: userStart, end: NaN })
6061
const user = api.authenticate('cookie-123')
6162
user.then(() => { calls.find(c => c.label==='authenticate')!.end = performance.now() - t0 })
@@ -83,19 +84,19 @@ export function App() {
8384
const t0 = performance.now()
8485
wrapFetch.setOrigin(t0)
8586
const calls: CallEvent[] = []
86-
const api1 = newHttpBatchRpcSession('/api')
87+
const api1 = newHttpBatchRpcSession<Api>('/api')
8788
const aStart = 0; calls.push({ label: 'authenticate', start: aStart, end: NaN })
8889
const uPromise = api1.authenticate('cookie-123')
8990
uPromise.then(() => { calls.find(c => c.label==='authenticate')!.end = performance.now() - t0 })
9091
const u = await uPromise
9192

92-
const api2 = newHttpBatchRpcSession('/api')
93+
const api2 = newHttpBatchRpcSession<Api>('/api')
9394
const pStart = performance.now() - t0; calls.push({ label: 'getUserProfile', start: pStart, end: NaN })
9495
const pPromise = api2.getUserProfile(u.id)
9596
pPromise.then(() => { calls.find(c => c.label==='getUserProfile')!.end = performance.now() - t0 })
9697
const p = await pPromise
9798

98-
const api3 = newHttpBatchRpcSession('/api')
99+
const api3 = newHttpBatchRpcSession<Api>('/api')
99100
const nStart = performance.now() - t0; calls.push({ label: 'getNotifications', start: nStart, end: NaN })
100101
const nPromise = api3.getNotifications(u.id)
101102
nPromise.then(() => { calls.find(c => c.label==='getNotifications')!.end = performance.now() - t0 })

0 commit comments

Comments
 (0)