Skip to content

React

SKDB's JavaScript libraries provide explicit support for working with React.

API

SKDBProvider

  • Purpose: Provide a local database object as context, to avoid passing it around as an explicit parameter to React components.

  • Usage:

    <SKDBProvider skdb={skdb}>
      <YourApplication />
    </SKDBProvider>
    

  • Imports:
    import { SKDBProvider } from 'skdb-react'
    
  • Recommendation: You should consider using SKDBDevConsoleProvider instead of SKDBProvider during development. It will allow you to switch between users quickly and debug faster by watching the results of custom queries.

Inside a react component: useQuery

  • Purpose: Query the database in a React-friendly manner, akin to the exec function.
  • Advantage: React components refresh automatically upon underlying data alterations, thanks to the integration of the watch method.
  • Usage:
    const data = useQuery(query, parameters);
    
  • Imports:
    import { useQuery } from 'skdb-react'
    

Inside a react component: useSKDB

  • Purpose: Make modifications to the database.
  • Usage:
    const skdb = useSKDB();
    
  • Returns: A handle on the local database object for performing assorted database operations within a React component. This accesses the same database object placed in the context by the SKDBProvider or SKDBDevConsoleProvider component.
  • Imports:
    import { useSKDB } from 'skdb-react'