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

Function setConfigValue

examples/react/todo/src/components/TodoApp.tsx:49–91  ·  view source on GitHub ↗
(key: string, value: string)

Source from the content-addressed store, hash-verified

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
77 })
78 return
79 }
80 }
81
82 // If the config doesn't exist yet, create it
83 configCollection.insert({
84 id: Math.round(Math.random() * 1000000),
85 key,
86 value,
87 created_at: new Date(),
88 updated_at: new Date(),
89 })
90 }
91 }
92
93 const backgroundColor = getConfigValue(`backgroundColor`)
94 const titleColor = getComplementaryColor(backgroundColor)

Callers 1

handleColorChangeFunction · 0.70

Calls 2

updateMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected