Documents / @faasjs/browser

@faasjs/browser

FaasJS browser client.

If you use React or Vue, please use @faasjs/reactopen in new window or @faasjs/vue-pluginopen in new window.

License: MITopen in new windowNPM Versionopen in new window

Browser plugin for FaasJS.

Install

npm install @faasjs/browser

Use directly

import { FaasBrowserClient } from '@faasjs/browser'

const client = new FaasBrowserClient('/')

await client.action('func', { key: 'value' })

Use with SWR

import { FaasBrowserClient } from '@faasjs/browser'
import useSWR from 'swr'

const client = new FaasBrowserClient('/')

const { data } = useSWR(['func', { key: 'value' }], client.action)

Reference: Data Fetching - SWRopen in new window

Use with React Query

import { FaasBrowserClient } from '@faasjs/browser'
import { QueryClient } from 'react-query'

const client = new FaasBrowserClient('/')

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      queryFn: async ({ queryKey }) => client
        .action(queryKey[0] as string, queryKey[1] as any)
        .then(data => data.data),
    },
  },
})

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <YourApp />
    </QueryClientProvider>
  )
}

Classes

Type Aliases

Functions