@@ -43,6 +43,30 @@ type CreateReactOutputResult = ServerRenderResult | ReactElement | Promise<strin
4343
4444type RenderFunctionResult = ReactComponent | ServerRenderResult | Promise < string > ;
4545
46+ /**
47+ * Render functions are used to create dynamic React components or server-rendered HTML with side effects.
48+ * They receive two arguments: props and railsContext.
49+ *
50+ * @param props - The component props passed to the render function
51+ * @param railsContext - The Rails context object containing environment information
52+ * @returns A string, React component, React element, or a Promise resolving to a string
53+ *
54+ * @remarks
55+ * To distinguish a render function from a React Function Component:
56+ * 1. Ensure it accepts two parameters (props and railsContext), even if railsContext is unused, or
57+ * 2. Set the `renderFunction` property to `true` on the function object.
58+ *
59+ * If neither condition is met, it will be treated as a React Function Component,
60+ * and ReactDOMServer will attempt to render it.
61+ *
62+ * @example
63+ * // Option 1: Two-parameter function
64+ * const renderFunction = (props, railsContext) => { ... };
65+ *
66+ * // Option 2: Using renderFunction property
67+ * const anotherRenderFunction = (props) => { ... };
68+ * anotherRenderFunction.renderFunction = true;
69+ */
4670interface RenderFunction {
4771 ( props ?: any , railsContext ?: RailsContext , domNodeId ?: string ) : RenderFunctionResult ;
4872 // We allow specifying that the function is RenderFunction and not a React Function Component
@@ -67,10 +91,10 @@ export type { // eslint-disable-line import/prefer-default-export
6791export interface RegisteredComponent {
6892 name : string ;
6993 component : ReactComponentOrRenderFunction ;
70- // Indicates if the registered component is a Render-function.
71- // Render-functions receive two arguments: props and railsContext.
72- // They should return a string, React component, React element, or a Promise .
73- // These functions are used to create dynamic React components or server-rendered HTML.
94+ /**
95+ * Indicates if the registered component is a RenderFunction
96+ * @see RenderFunction for more details on its behavior and usage .
97+ */
7498 renderFunction : boolean ;
7599 // Indicates if the registered component is a Renderer function.
76100 // Renderer function handles DOM rendering or hydration with 3 args: (props, railsContext, domNodeId)
0 commit comments