MCPcopy Index your code
hub / github.com/reactjs/server-components-demo / performMutation

Function performMutation

src/framework/router.js:88–113  ·  view source on GitHub ↗
(payload, requestedLocation)

Source from the content-addressed store, hash-verified

86 }
87
88 async function performMutation(payload, requestedLocation) {
89 setIsSaving(true);
90 try {
91 const response = await fetch(
92 `${endpoint}?location=${encodeURIComponent(
93 JSON.stringify(requestedLocation)
94 )}`,
95 {
96 method,
97 body: JSON.stringify(payload),
98 headers: {
99 'Content-Type': 'application/json',
100 },
101 }
102 );
103 if (!response.ok) {
104 throw new Error(await response.text());
105 }
106 refresh(response);
107 } catch (e) {
108 setDidError(true);
109 setError(e);
110 } finally {
111 setIsSaving(false);
112 }
113 }
114
115 return [isSaving, performMutation];
116}

Callers

nothing calls this directly

Calls 1

refreshFunction · 0.85

Tested by

no test coverage detected