${post.title}
${post.content}
# JavaScript SDK ## Overview The JavaScript SDK is the primary way to interact with PocketBase from frontend applications. It's available via CDN or npm package. ## Installation ### Via CDN ```html ``` ### Via npm ```bash npm install pocketbase ``` ```javascript import PocketBase from 'pocketbase'; const pb = new PocketBase('http://127.0.0.1:8090'); ``` ## Initialization ```javascript const pb = new PocketBase('http://127.0.0.1:8090'); ``` For advanced configuration (custom auth store, language, fetch implementation, etc.), refer to the [official JS SDK README](https://github.com/pocketbase/js-sdk). ## Core Features ### Authentication - User registration and login - OAuth2 integration - Auth state management - JWT token handling ### Data Operations - CRUD operations on collections - Filtering, sorting, pagination - Relation expansion - Batch operations ### Realtime - WebSocket subscriptions - Live updates - Event handling ### File Management - File uploads - File URL generation - Thumbnail access ## Common Use Cases ### React Integration ```javascript import { useEffect, useState } from 'react'; import PocketBase from 'pocketbase'; const pb = new PocketBase('http://127.0.0.1:8090'); function useAuth() { const [user, setUser] = useState(pb.authStore.model); useEffect(() => { const unsub = pb.authStore.onChange(() => { setUser(pb.authStore.model); }); return () => unsub(); }, []); return { user }; } function PostsList() { const [posts, setPosts] = useState([]); const { user } = useAuth(); useEffect(() => { loadPosts(); // Subscribe to realtime updates pb.collection('posts').subscribe('*', () => { loadPosts(); }); return () => pb.collection('posts').unsubscribe(); }, []); async function loadPosts() { const records = await pb.collection('posts').getList(1, 50); setPosts(records.items); } async function createPost(data) { await pb.collection('posts').create(data); } return (
${post.content}