@faasjs/browser
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

@faasjs/browser

FaasJS browser client.

If you use React or Vue, please use @faasjs/react or @faasjs/vue-plugin.

License: MIT NPM Version

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 - SWR

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

Versions

Current Tags

Version History

Package Sidebar

Install

npm i @faasjs/browser

Weekly Downloads

140

Version

2.2.0

License

MIT

Unpacked Size

21.5 kB

Total Files

7

Last publish

Collaborators

  • zfben