@faasjs/browser
v3.7.1
Published
FaasJS browser client.
Downloads
2,391
Readme
@faasjs/browser
FaasJS browser client.
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 - 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>
)
}
Use with React
Please use @faasjs/react for React.
Use with Vue
Please use @faasjs/vue-plugin for Vue.