Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

source-id-reuse-support.tsx

33 lines949 Bytes

1import { Component } from 'react'
2import { createCollection } from '@tanstack/db'
3import { mockSyncCollectionOptions } from '../../db/tests/utils'
4import type { ReactNode } from 'react'
5​
6// Shared fixtures for the React source ID reuse tests. The reuse law is owned by
7// source-id-reuse-oracle.test.tsx; ordinary pinned tests live in source-id-reuse.test.tsx.
8export type Row = { id: string; value: string; rank: number }
9​
10export class TestErrorBoundary extends Component<
11 { children: ReactNode },
12 { error?: Error }
13> {
14 state: { error?: Error } = {}
15​
16 static getDerivedStateFromError(error: Error) {
17 return { error }
18 }
19​
20 render() {
21 return this.state.error ? <div>Rejected</div> : this.props.children
22 }
24​
25export function source(id: string, value: string) {
26 return createCollection(
27 mockSyncCollectionOptions<Row>({
28 id,
29 getKey: (row) => row.id,
30 initialData: [{ id: `one`, value, rank: 1 }],
31 }),
32 )