Skip to content

Function ​

tsx
import React from "react"
import { createRoot, Function } from '@kubb/react'

const root = createRoot()

const Component = () => {
  return (
    <Function name="getData" export async>
      return 2;
    </Function>
  )
}

root.render(<Component />)
root.output
//   ^?
typescript
export async function getData() {
  return 2
}

API ​

tsx
import React from "react"
import { Function } from '@kubb/react'

type Props = React.ComponentProps<typeof Function>
PropertyDescriptionTypeDefault
nameName of the function.string-
paramsParameters/options/props that need to be used.string | undefined-
exportDoes this function need to be exported.boolean | undefined-
asyncDoes the function has async/promise behaviour.boolean | undefined-
genericsGenerics that needs to be added for TypeScript.string | string[] | undefined-
returnTypeReturnType(see async for adding Promise type).string | undefined-
JSDocOptions for JSdocsJSDoc | undefined-
childrenKubbNode | undefined-

Released under the MIT License.