Standard Resource
  • Introduction
  • Read Me
  • Introduction
    • Motivation
    • Core Concepts
  • Store
    • Creating a Store
  • Resources
    • Resource Data
    • Creating
    • Retrieving
    • Updating
    • Deleting
    • Using Computed Attributes
    • Schemas
  • Groups
    • Creating
    • Retrieving
    • Updating
    • Deleting
    • Sorted Groups
  • API Reference
    • createResourceStore
    • Store
  • Glossary
  • Changelog
Powered by GitBook
On this page
  • Initial State
  • Passing options
  • Using the store
  • Tips
  1. Store

Creating a Store

PreviousStoreNextResources

Last updated 7 years ago

Creating a is the first thing you must do when getting started with Standard Resource.

The default export of the library is called ; it is a function that returns a store.

import createResourceStore from 'standard-resource';

const store = createResourceStore();

Because a store contains all of your , you only need a single store for your application.

Initial State

Sometimes, you may want to instantiate a store with initial data. Typically, this feature is used when building progressive web apps, or universal apps.

import createResourceStore from 'standard-resource';

const store = createResourceStore(initialState);

In the above example, initialState should be an entire state tree. If you have a store, you can access the state tree by calling .

Passing options

createResourceStore accepts a second argument, options. This allows you to further configure the store.

Presently, there is only one option: schemas. Use this option to configure the store with the for your resource types.

import createResourceStore from 'standard-resource';
import booksSchema from './books/schema';
import moviesSchema from './movies/schema';
import authorsSchema from './authors/schema';

const store = createResourceStore(null, {
  schemas: {
    books: booksSchema,
    movies: moviesSchema,
    authors: authorsSchema,
  },
});

Using the store

The store has helpful methods to create and update resources and groups. The following guides will cover how you can do those things.

Tips

  • There should only ever be one store in each application.

createResourceStore
store.getState()
store
resource data
schemas