The StoreProvider creates one global store instance that can be observed across the application. This allows different modules and components to all hook into and observe the same store. StoreProvider also creates a single API instance that uses the store from context to reactively update the shared store.
import { StoreProvider, cache } from 'perch-data';
const App = () => (
<StoreProvider
api={axiosInstance}
initialValues={{ foo: 'bar' }}
store={cache}
>
<YourApp />
</StoreProvider>
);
api: AxiosInstance
- This instance of Axios will be wrapped in AxiosStore and use the store from contextstore: Object
- RequiredobserveData: Function
- Required Returns data from the cache or fetches it - see code for signature - must return an id for unsubscribingunobserveData: Function
- Required Accepts an id and stops observing it
initialValues: Object
- This is a function to pre-populate your store with default values. If the value is already in the store (persisted) it will not be overwritten.