You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/pwa-kit-mcp/src/tools/developer-guideline.js
+54Lines changed: 54 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -99,6 +99,60 @@ This document offers guidelines in the development of Salesforce Commerce Compos
99
99
- Use kebab-case for file names. Only start with an underscore (_) if they are special components.
100
100
- Use React Hooks (e.g., useState, useEffect, useContext, useMemo, useCallback) for state management and side effects.
101
101
102
+
### Custom API Implementation
103
+
- Use 'useCustomQuery' or 'useCustomMutation' hooks from 'commerce-sdk-react'
104
+
- **DON'T** include any extra '/' before or after path parameters in the 'customApiPathParameters' object
105
+
- Parameters for 'useCustomQuery' or 'useCustomMutation':
106
+
- \`options\` (Object): Configuration for the API request.
107
+
- \`method\` (String): The HTTP method to use (e.g., 'POST', 'GET').
108
+
- \`customApiPathParameters\` (Object): Contains parameters to define the API path.
109
+
- \`endpointPath\` (String): Specific endpoint path to target in the API.
110
+
- \`apiName\` (String): The name of the API
111
+
- \`useCustomQuery\` usage :
112
+
\`\`\`jsx
113
+
const query = useCustomQuery(
114
+
{
115
+
options: {
116
+
method: 'GET',
117
+
customApiPathParameters: {
118
+
apiName: 'your-api-name',
119
+
apiVersion: 'your-api-version',
120
+
endpointPath: 'your-endpoint'
121
+
},
122
+
parameters: {
123
+
c_yourParam: params.yourParam,
124
+
// other parameters
125
+
}
126
+
}
127
+
}
128
+
)
129
+
\`\`\`
130
+
#### \`mutate\` Method
131
+
The \`mutation.mutate(args)\` function is used to execute the mutation. It accepts an argument \`args\`, which is an object that may contain the following properties:
132
+
- \`headers\` (Object): Optional headers to send with the request.
133
+
- \`parameters\` (Object): Optional query parameters to append to the API URL.
134
+
- \`body\` (Object): Optional the payload for POST, PUT, PATCH methods.
135
+
- \`useCustomMutation\` usage:
136
+
\`\`\`jsx
137
+
const mutation = useCustomMutation({
138
+
options: {
139
+
method: 'POST',
140
+
customApiPathParameters: {
141
+
apiName: 'your-api-name',
142
+
apiVersion: 'your-api-version',
143
+
endpointPath: 'your-endpoint'
144
+
}
145
+
}
146
+
});
147
+
148
+
// In your React component
149
+
<button onClick={() => mutation.mutate({
150
+
body: { test: '123' },
151
+
parameters: { additional: 'value' },
152
+
headers: { ['X-Custom-Header']: 'test' }
153
+
})}> Send Request </button>
154
+
\`\`\`
155
+
102
156
## Quality Standards
103
157
- Maintain consistent code formatting using project standards.
0 commit comments