MCPcopy Create free account
hub / github.com/Nutlope/llamacoder / CodeRunnerServerAction

Function CodeRunnerServerAction

components/code-runner-server-action.tsx:7–43  ·  view source on GitHub ↗
({
  code,
  runCodeAction,
}: {
  code: string;
  runCodeAction: (v: string) => Promise<string>;
})

Source from the content-addressed store, hash-verified

5import { useActionState } from "react";
6
7export default function CodeRunnerServerAction({
8 code,
9 runCodeAction,
10}: {
11 code: string;
12 runCodeAction: (v: string) => Promise<string>;
13}) {
14 const [state, action, isPending] = useActionState(async () => {
15 return runCodeAction(code);
16 }, null);
17
18 return (
19 <div>
20 {state === null ? (
21 <div className="flex flex-col items-center justify-center">
22 <p>Run the code to generate an output</p>
23
24 <form action={action} className="mt-4">
25 <button
26 disabled={isPending}
27 className="inline-flex rounded border border-gray-300 px-2.5 py-1 text-sm text-gray-600 transition enabled:hover:bg-gray-100 disabled:opacity-75"
28 >
29 <Spinner loading={isPending}>
30 <span className="inline-flex items-center gap-1">
31 <PlayIcon className="size-4" />
32 Run Code
33 </span>
34 </Spinner>
35 </button>
36 </form>
37 </div>
38 ) : (
39 <div>{state}</div>
40 )}
41 </div>
42 );
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected