
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
mobx-state-tree-firebase
Advanced tools
This package will ease the process of setting up all your CRUD operations in your react-native/react project which uses mobx-state-tree as the state management library.
You will need -
Node (v6+)
npm (v3+)
Installing is pretty straightforward, if you have the prerequisites set up. Just copy the below code to your terminal in your project directory. Note that this has a peer dependency of mobx and firebase (duh!).
npm install mst-firebase --save
Now that you have installed the package you are all set to start playing with it!
First, import the package to wherever you need to save the mst model.
import { FirebaseModel } from 'FirebaseModel';
This will only provide the save/update function, to get all the other functions you can import them seperately like
import { findById } from 'FirebaseModel';
import { findAllWhere } from 'FirebaseModel';
Next you have to "inherit" all the properties of the FirebaseModel to your mobx-state-tree model. An example for this would be -
const Post = FirebaseBaseModel.named("Post")
.props({
_path: "posts",
title: types.string,
description: types.string
})
.actions((self) => {
return {
updateTitle(newTitle: string) {
self.title = newTitle;
},
};
});
Now that Let's go over some common use cases.
const FirstPost = Post.create({
title: 'Hey!',
description: 'Please save this.',
});
FirstPost.save();
And voila! A new post is added!
const FirstPost = Post.create({
title: 'Hey!',
description: 'updated?',
_id: "-Kw4VJxqhKSiA3r2K8ue"
});
FirstPost.save();
findById(
YourModel,
IdYouWantToGet)
.then(success =>
//do stuff on success here
}, error => {
//do stuff on error here
});
The first argument is your mobx-state-tree model and the second argument is the Id of the object you are trying to access.
Let us look at an example where we want to fetch a user with a particular user id.
findById(Post, "-Kw0DPoUeMBtsB-ZrZdQ").then(success => {
console.log("success", getSnapshot(success));
});
findAllWhere(
YourModel,
PropYouWantToFilterBy,
OperatorYouWantToFilterBy,
ValueYouWantToFilterBy)
.then(success =>
//do stuff on success here
}, error => {
//do stuff on error here
});
);
Note that the first argument is your mobx-state-tree model, second is the column on which you want to add the condition, third is the operator(supported operators right now are =,>,< and between), fourth is the value to filter by.
Let us look at an example where we want to fetch all posts with the title as Lorem ipsum.
findAllWhere(Post, 'title', '=', 'Lorem ipsum').then(success => {
console.log("success", success);
});
This project is licensed under the MIT License - see the LICENSE.md file for details
FAQs
Firebase Integration for mobx-state-tree
We found that mobx-state-tree-firebase demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.