-
Hello, I have a question regarding the example.client.ts generated by generate-client.ts found here: https://github.com/RobinTail/express-zod-api/blob/master/example/generate-client.ts Let's say we define the output as follows:
This would generate an example.client.ts like:
When using the generated example.client.ts to call the API and setting the value using useState, is there a way to extract only the type for success? Is this the only way to do it?
Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @yuuri111 , The thing you asked for: The thing you didn't ask for: const client = new ExpressZodAPIClient(async (method, path, params) => {
// ... shortened
return response.json();
});
export const getSomething = async () => {
const response = await client.provide("get", "/v1/something", {});
if (response.status === "error") {
throw new Error(response.error.message);
}
return response.data.thatThing;
}; In this case, useState<ReturnType<typeof getSomething> | null>(null) I hope that helps. |
Beta Was this translation helpful? Give feedback.
-
This works great! Thank you. |
Beta Was this translation helpful? Give feedback.
Hello @yuuri111 ,
The thing you asked for:
splitResponse
option in theIntegration::constructor()
argument (added in v16.0.0).The thing you didn't ask for:
In this case,
getSomething()
only returns the positive response and there is no need toExtract
it.So that in your React App you can do