MCPcopy Create free account
hub / github.com/electric-sql/electric / createItem

Function createItem

examples/encryption/src/Example.tsx:114–141  ·  view source on GitHub ↗
(event: React.FormEvent)

Source from the content-addressed store, hash-verified

112 * and sending it to the API
113 */
114 async function createItem(event: React.FormEvent) {
115 event.preventDefault()
116
117 const form = event.target as HTMLFormElement
118 const formData = new FormData(form)
119 const title = formData.get(`title`) as string
120
121 const id = crypto.randomUUID()
122 const item = {
123 id,
124 title,
125 }
126
127 const data = await encrypt(item)
128
129 const url = `${API_URL}/items`
130 const options = {
131 method: `POST`,
132 body: JSON.stringify(data),
133 headers: {
134 'Content-Type': `application/json`,
135 },
136 }
137
138 await fetch(url, options)
139
140 form.reset()
141 }
142
143 if (items === undefined) {
144 return <div>Loading...</div>

Callers

nothing calls this directly

Calls 4

encryptFunction · 0.85
fetchFunction · 0.85
resetMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected