Documents / @faasjs/browser

@faasjs/browser

FaasJS browser client.

License: MITopen in new windowNPM Versionopen in new window

Browser plugin for FaasJS.

Install

npm install @faasjs/browser

Usage

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>
  )
}

Use with React

Please use @faasjs/reactopen in new window for React.

Use with Vue

Please use @faasjs/vue-pluginopen in new window for Vue.

Classes

Type Aliases

Functions