Insert Items
RefinerDB wants to know your full set of items (prior to any filtering, sorting, or paging).
You can pass your items to the RefinerDBProvider
or you can call setItems
on
the RefinerDB
instance provided by useRefinerDB
.
// Option 1: Pass items to the RefinerDBProvider
<RefinerDBProvider
name="movies"
items={movies}
indexes={movieIndexes} >
<YourStuff />
</RefinerDBProvider>
// Option 1b: Pass items to the RefinerDBProvider
// and specify the primary key
<RefinerDBProvider
name="movies"
items={movies}
{/* If you don't pass an `idProperty` RefinerDB will assume it is "id". */}
idProperty="movieId"
indexes={movieIndexes} >
<YourStuff />
</RefinerDBProvider>
// Option 2: Set items explicitely
// Assumes your component is already
// wrapped with a `RefinerDBProvider`.
let refinerDB = useRefinerDB();
refinerDB.setItems(movies);
- The items can be in any shape.
- But each item needs to have a property that represents the primary key.
- The primary key can be an
string
or anumber
- The primary key can be an
- By default RefinerDB assumes that property is
id
- When creating a database, you can explicitely tell RefinerDB what the primary key is using the
idProperty
setting.
let refinerDB = new RefinerDB("bookmarks", { idProperty: "__id" });
If you are using refinerdb-react
, you can pass the items to the RefinerDBProvider
or
you can set them explcitely using the useRefinerDB
hook.