Creating the Store
Learn how to set up MobX store and integrate it with React Native App.
We will start with setting up a store; this will be the source of truth for the app. But before adding and removing images, there’s one more step we need to take. We need to hook up the store!
Creating an empty store
Let’s go to our store.js
file and tell it to use the User
and LikedImages
models. We’ll start by importing all the necessary files and creating an empty store:
Press + to interact
// ./store.jsimport { types, flow, applySnapshot } from "mobx-state-tree"import { LikedImages } from "./src/models/LikedImages";import { User } from './src/models/User';// Define the root store model, including users and likedImagesconst RootStore = types.model({users: User,likedImages: LikedImages})// Create an instance of the RootStore with initial dataexport const store = RootStore.create({users: {}, // Placeholder for user datalikedImages: {} // Placeholder for liked images data})// Add comments as needed to describe the purpose and structure of the code
We import the two models
ImportImages
andUser
on lines ...