besimking
besimking
Explore posts from servers
CCConvex Community
Created by besimking on 12/28/2024 in #support-community
Generic Query and Mutations
@erquhart @Lee Thanks a lot! You are the best
8 replies
CCConvex Community
Created by besimking on 12/28/2024 in #support-community
Generic Query and Mutations
Has anyone done something like this before?
8 replies
CCConvex Community
Created by besimking on 12/28/2024 in #support-community
Generic Query and Mutations
I need a structure like
const { data, isPending } = useConvexQuery(api.example.getExamples);

const { mutate, isPending } = useConvexMutation(api.example.createExamples);

const { mutate, isPending } = useConvexMutation(api.example.editExamples,{name:"Something",text:"Another Thing");
const { data, isPending } = useConvexQuery(api.example.getExamples);

const { mutate, isPending } = useConvexMutation(api.example.createExamples);

const { mutate, isPending } = useConvexMutation(api.example.editExamples,{name:"Something",text:"Another Thing");
8 replies
CCConvex Community
Created by besimking on 12/28/2024 in #support-community
Generic Query and Mutations
or
import { useMutation } from "convex/react";
import { useCallback, useMemo, useState } from "react";
import { Id } from "../../../../convex/_generated/dataModel";
import { api } from "../../../../convex/_generated/api";


type ResponseType = Id<"restaurants"> | null;
type RequestType = {
name: string;
text: string;

};

type Options = {
onSuccess?: (data: ResponseType) => void;
onError?: (error: Error) => void;
onSettled?: () => void;
throwError?: boolean;
};

export const useCreateExample = () => {
const [data, setData] = useState<ResponseType>(null);
const [error, setError] = useState<Error | null>(null);

const [status, setStatus] = useState<
"success" | "error" | "settled" | "pending" | null
>(null);

const isPending = useMemo(() => status === "pending", [status]);
const isSuccess = useMemo(() => status === "success", [status]);
const isError = useMemo(() => status === "error", [status]);
const isSettled = useMemo(() => status === "settled", [status]);

const mutation = useMutation(api.examples.createExamples);

const mutate = useCallback(
async (values: RequestType, options?: Options) => {
try {
setData(null);
setError(null);
setStatus("pending");

const response = await mutation({
name: values.name,
currency: values.currency,
image: values.image,
});
options?.onSuccess?.(response);
return response;
} catch (error) {
setStatus("error");
options?.onError?.(error as Error);
if (options?.throwError) {
throw error;
}
} finally {
setStatus("settled");
options?.onSettled?.();
}
},
[mutation],
);

return { mutate, data, error, isPending, isSuccess, isError, isSettled };
};
import { useMutation } from "convex/react";
import { useCallback, useMemo, useState } from "react";
import { Id } from "../../../../convex/_generated/dataModel";
import { api } from "../../../../convex/_generated/api";


type ResponseType = Id<"restaurants"> | null;
type RequestType = {
name: string;
text: string;

};

type Options = {
onSuccess?: (data: ResponseType) => void;
onError?: (error: Error) => void;
onSettled?: () => void;
throwError?: boolean;
};

export const useCreateExample = () => {
const [data, setData] = useState<ResponseType>(null);
const [error, setError] = useState<Error | null>(null);

const [status, setStatus] = useState<
"success" | "error" | "settled" | "pending" | null
>(null);

const isPending = useMemo(() => status === "pending", [status]);
const isSuccess = useMemo(() => status === "success", [status]);
const isError = useMemo(() => status === "error", [status]);
const isSettled = useMemo(() => status === "settled", [status]);

const mutation = useMutation(api.examples.createExamples);

const mutate = useCallback(
async (values: RequestType, options?: Options) => {
try {
setData(null);
setError(null);
setStatus("pending");

const response = await mutation({
name: values.name,
currency: values.currency,
image: values.image,
});
options?.onSuccess?.(response);
return response;
} catch (error) {
setStatus("error");
options?.onError?.(error as Error);
if (options?.throwError) {
throw error;
}
} finally {
setStatus("settled");
options?.onSettled?.();
}
},
[mutation],
);

return { mutate, data, error, isPending, isSuccess, isError, isSettled };
};
8 replies
CCConvex Community
Created by besimking on 12/4/2024 in #support-community
Cron Jobs, Actions, Internal Mutation
Problem solved. Princess saved. Thanks Spider-Man World Peace ☮️
28 replies
CCConvex Community
Created by besimking on 12/4/2024 in #support-community
Cron Jobs, Actions, Internal Mutation
I am trying
28 replies
CCConvex Community
Created by besimking on 12/4/2024 in #support-community
Cron Jobs, Actions, Internal Mutation
Yeah I've found that out 🤣 I am sorry for this
28 replies
CCConvex Community
Created by besimking on 12/4/2024 in #support-community
Cron Jobs, Actions, Internal Mutation
How exactly?
28 replies