Gathering detailed insights and metrics for mobx-store-provider
Gathering detailed insights and metrics for mobx-store-provider
Gathering detailed insights and metrics for mobx-store-provider
Gathering detailed insights and metrics for mobx-store-provider
npm install mobx-store-provider
Maintenance release
Published on 05 Jan 2022
Minor bug fix
Published on 23 Mar 2021
Added minor feature
Published on 22 Mar 2021
Maintenance release
Published on 20 Mar 2021
Maintenance release
Published on 21 Dec 2020
Missing env proxy for useCreateStore
Published on 29 Nov 2020
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
42 Stars
932 Commits
3 Forks
3 Watching
3 Branches
1 Contributors
Updated on 04 Jul 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-19.4%
187
Compared to previous day
Last week
-29.8%
1,216
Compared to previous week
Last month
20.9%
6,948
Compared to previous month
Last year
36.2%
62,624
Compared to previous year
2
mobx-store-provider is a library that provides React Hooks to setup and access mobx-state-tree models from within React Function Components.
Its goal is to provide a straight-forward, minimalist, and terse API that allows you to easily incorporate mobx-state-tree into functional React components.
1npm i mobx-store-provider
1yarn add mobx-store-provider
The following shows an example application using mobx-store-provider.
At the core of the application we define the main App
component.
Inside of the App
we use hooks provided by mobx-store-provider to:
appStore
instance with the useCreateStore hookProvider
with the useProvider hook1// App.jsx (Main App component, we use it to create and provide the store) 2import React from "react"; 3import { useProvider, useCreateStore } from "mobx-store-provider"; 4import AppStore from "./AppStore"; 5import UserDisplay from "./UserDisplay"; 6 7function App() { 8 // Create the AppStore instance 9 const appStore = useCreateStore(AppStore, { user: "Jonathan" }); 10 11 // Get the Provider for the AppStore 12 const Provider = useProvider(AppStore); 13 14 // Wrap the application with the Provider passing it the appStore 15 return ( 16 <Provider value={appStore}> 17 <UserDisplay /> 18 </Provider> 19 ); 20} 21 22export default App;
Note that we wrap the application with the Provider
, supplying it the appStore
as its value.
This makes the appStore
available to the rest of the application.
In another component somewhere in the application we want to use or gain access to the appStore
.
To do this, we use the useStore hook:
1// UserDisplay.jsx (A component, we use the store from above inside it) 2import React from "react"; 3import { observer } from "mobx-react"; 4import { useStore } from "mobx-store-provider"; 5import AppStore from "./AppStore"; 6 7function UserDisplay() { 8 // Get access to the store 9 const appStore = useStore(AppStore); 10 return <div>{appStore.user}</div>; 11} 12 13// Wrap it with mobx-react observer(), so updates get rendered 14export default observer(UserDisplay);
Note that we also wrap the component with observer()
from the mobx-react library.
This is critical, as it ensures the component will render any updates made to the appStore
. For more information, see the observer documentation for the mobx-react library.
The code above uses the AppStore
mobx-state-tree model. In the context of mobx-store-provider this is referred to as a store
.
1// AppStore.js (mobx-state-tree store/model) 2import { types } from "mobx-state-tree"; 3 4const AppStore = types.model({ 5 user: types.string, 6}); 7 8export default AppStore;
If you are new to mobx-state-tree, it is recommended you read through the mobx-state-tree documentation.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
7 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/18 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More