MobxCache
An observable data cache with MobX.
Installation
If using npm to manage your dependencies, you can easily do:
npm install --save mobx-cache
Also, make sure mobx
is installed since this library relies on it.
Example 1: Simple hello world
var helloMessages = `Hello, ` const HelloWorldApp = React // The next line will update the cache and cause `HelloWorldApp` to re-render// with the new message:helloMessages
The above example is for demonstration purposes only. It may not be useful in real life. This library is especially useful when used for data fetching as the next example shows.
Example 2: User profile
var usersCache = const UserProfile = // Rendering with the id 199 will cause the fetching of user 199.React // When we render with a different id, the new user will be fetched and rendered.React
The fetch
function can be any function that sends a request to the given url and returns a promise. The promise will automatically be handlded by MobxCache.