atm
CCConvex Community
•Created by atm on 9/8/2023 in #support-community
Question about how actions and calling 3rd party apis work, and .env variables.
I read the docs on these but it's still not really clear to me how things work and connect together.
I want to pass params so i can add a query or body to the fetch call in doSomething action from react front end code. Is this possible?
These were the examples in the docs.
import { action } from "./_generated/server";
export const doSomething = action({
args: {},
handler: async () => {
const data = await fetch("https://api.thirdpartyservice.com");
return data
},
});
import React from "react";
import { useAction } from "convex/react";
import { api } from "../convex/_generated/api";
export function MyApp() {
const performMyAction = useAction(api.myFunctions.doSomething);
const handleClick = () => {
performMyAction({ a: 1 });
};
// pass
handleClick to a button
// ...
}
4 replies