Skip to content

Commit fdc3299

Browse files
committed
Add use action hook
Signed-off-by: Marcos Candeia <[email protected]>
1 parent 68c031b commit fdc3299

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Diff for: blocks/section.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PartialProps } from "$fresh/src/runtime/Partial.tsx";
33
import { ComponentType } from "preact";
44
import { HttpContext } from "../blocks/handler.ts";
55
import { PropsLoader, propsLoader } from "../blocks/propsLoader.ts";
6-
import { fnContextFromHttpContext, RequestState } from "../blocks/utils.tsx";
6+
import { RequestState, fnContextFromHttpContext } from "../blocks/utils.tsx";
77
import StubSection, { Empty } from "../components/StubSection.tsx";
88
import { withSection } from "../components/section.tsx";
99
import { Context } from "../deco.ts";
@@ -44,9 +44,13 @@ export const isSection = <
4444
return (s as Section)?.metadata?.component === section;
4545
};
4646

47-
export type SectionProps<T> = T extends PropsLoader<any, infer Props> ? Props
47+
type ReturnProps<TFunc> = TFunc extends PropsLoader<any, infer Props> ? Props
4848
: unknown;
4949

50+
export type SectionProps<LoaderFunc, ActionFunc = LoaderFunc> =
51+
| ReturnProps<LoaderFunc>
52+
| ReturnProps<ActionFunc>;
53+
5054
export interface ErrorBoundaryParams<TProps> {
5155
error: any;
5256
props: TProps;
@@ -59,7 +63,7 @@ export interface SectionModule<
5963
TConfig = any,
6064
TProps = any,
6165
TLoaderProps = TProps,
62-
TActionProps = TProps,
66+
TActionProps = TLoaderProps,
6367
> extends
6468
BlockModule<
6569
ComponentFunc<TLoaderProps | TActionProps>,

Diff for: components/Form.tsx

-8
This file was deleted.

Diff for: hooks/useAction.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { usePartialSection } from "./usePartialSection.ts";
2+
3+
/**
4+
* @returns the action url of the current section.
5+
*/
6+
export const useAction = () => {
7+
return usePartialSection()["f-partial"];
8+
};

0 commit comments

Comments
 (0)