FaasJS
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文

Documents / @faasjs/func / useFunc

Function: useFunc()

useFunc<TEvent, TContext, TResult>(handler): Func<TEvent, TContext, TResult>

Create a cloud function.

Type Parameters

TEvent

TEvent = any

TContext

TContext = any

TResult

TResult = any

Parameters

handler

() => Handler<TEvent, TContext, TResult>

Returns

Func<TEvent, TContext, TResult>

Example

// pure function
export const func = useFunc(() => {
  return () => {
    return 'Hello World'
  }
})

// with http
import { useHttp } from '@faasjs/http'

export const func = useFunc<{
  params: { name: string }
}>(() => {
  useHttp()

  return ({ event }) => {
    return `Hello ${event.params.name}`
  }
})