MCPcopy Create free account
hub / github.com/TanStack/db / TodoApp

Function TodoApp

examples/react/todo/src/components/TodoApp.tsx:19–237  ·  view source on GitHub ↗
({
  todos,
  configData,
  todoCollection,
  configCollection,
  title,
  configMutationFn,
}: TodoAppProps)

Source from the content-addressed store, hash-verified

17}
18
19export function TodoApp({
20 todos,
21 configData,
22 todoCollection,
23 configCollection,
24 title,
25 configMutationFn,
26}: TodoAppProps) {
27 const [newTodo, setNewTodo] = useState(``)
28
29 // Use paced mutations with debounce strategy for color picker if mutationFn provided
30 // Waits for 2500ms of inactivity before persisting - only the final value is saved
31 const mutateConfig = configMutationFn
32 ? usePacedMutations({
33 mutationFn: configMutationFn,
34 strategy: debounceStrategy({ wait: 2500 }),
35 })
36 : undefined
37
38 // Define a type-safe helper function to get config values
39 const getConfigValue = (key: string): string | undefined => {
40 for (const config of configData) {
41 if (config.key === key) {
42 return config.value
43 }
44 }
45 return undefined
46 }
47
48 // Define a helper function to update config values
49 const setConfigValue = (key: string, value: string): void => {
50 if (mutateConfig) {
51 // Use paced mutations for updates (optimistic + batched persistence)
52 mutateConfig(() => {
53 for (const config of configData) {
54 if (config.key === key) {
55 configCollection.update(config.id, (draft) => {
56 draft.value = value
57 })
58 return
59 }
60 }
61
62 // If the config doesn't exist yet, create it
63 configCollection.insert({
64 id: Math.round(Math.random() * 1000000),
65 key,
66 value,
67 created_at: new Date(),
68 updated_at: new Date(),
69 })
70 })
71 } else {
72 // Use naked collection calls (collection handlers will be invoked)
73 for (const config of configData) {
74 if (config.key === key) {
75 configCollection.update(config.id, (draft) => {
76 draft.value = value

Callers

nothing calls this directly

Calls 9

usePacedMutationsFunction · 0.90
getComplementaryColorFunction · 0.90
debounceStrategyFunction · 0.85
filterMethod · 0.80
getConfigValueFunction · 0.70
updateMethod · 0.45
mapMethod · 0.45
forEachMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected