Gathering detailed insights and metrics for with-mobx-store
Gathering detailed insights and metrics for with-mobx-store
Gathering detailed insights and metrics for with-mobx-store
Gathering detailed insights and metrics for with-mobx-store
npm install with-mobx-store
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
16 Commits
1 Forks
5 Watchers
1 Branches
6 Contributors
Updated on Jan 28, 2023
Latest Version
1.1.6
Package Id
with-mobx-store@1.1.6
Unpacked Size
1.02 MB
Size
290.27 kB
File Count
13
NPM Version
6.4.1
Node Version
10.15.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
with-mobx-store is higher order components library for performing automated MobX Provider wrapping.
npm i mobx mobx-react with-mobx-store
yarn add mobx mobx-react with-mobx-store
When you want to work with MobX store, you have to create at least two components
to work with it as the following example below.
1import React from 'react' 2import { Provider } from 'mobx' 3import DataHandler from './DataList' 4import DataStore from './store' 5const dataStore = new DataStore() 6const DataListContainer = () => ( 7 <Provider dataStore={dataStore}> 8 <DataHandler /> 9 </Provider> 10) 11export default DataListContainer
I want to inject DataStore
to DataHandler
. I have to create a component for wrapping DataHandler
with Provider
. After that I have to create another component DataHandler
to inject dataStore
to it like the following code.
1import React, { Fragment } from 'react' 2import { inject, observer } from 'mobx-react' 3import DataItem from './DataItem' 4import { compose } from 'recompose' 5const DataHandler = ({ dataStore }) => ( 6 <Fragment> 7 { dataStore.data.map(datum => ( 8 <DataItem 9 key={datum.id} 10 {...datum} 11 /> 12 ) } 13 </Fragment> 14) 15export default compose( 16 inject('dataStore'), 17 observer, 18)(DataHandler)
Is it better if we don't have to create two new component just use the higher order component to wrap our target componnent?
This is why we create with-mobx-store
withStore
is a higher order component (HOC) that allow you to initialize component without wraping any provider.
You just simply wrap your component with withStore
, then it's worked!
stores
- Object for mapping name of store with store object.options
- Options for modifying store lifecycle1import React from 'react' 2import { inject, observer } from 'mobx-react' 3import { compose } from 'recompose' 4import { withStore } from 'with-mobx-store' 5import DataItem from './DataItem' 6import DataStore from './store' 7const DataHandler = ({ dataStore }) => ( 8 <Fragment> 9 { dataStore.data.map(datum => ( 10 <DataItem 11 key={datum.id} 12 {...datum} 13 /> 14 ) } 15 </Fragment> 16) 17export default compose( 18 withStore({ 19 dataStore: new DataStore(), 20 }), 21 inject('dataStore'), 22 observer, 23)(DataHandler)
withComponentStore
is higher order component (HOC) that allow you to initialize component without wraping any provider.
Moreover, it works specifically with stores per component.
stores
- Object for mapping name of store with store class.options
- Options for modifying store lifecycle.1import React from 'react' 2import { inject, observer } from 'mobx-react' 3import { compose } from 'recompose' 4import { withComponentStore } from 'with-mobx-store' 5import DataItem from './DataItem' 6import DataStore from './stores/DataStore' 7const DataHandler = ({ data }) => ( 8 <Fragment> 9 { dataStore.data.map(datum => ( 10 <DataItem 11 key={datum.id} 12 {...datum} 13 /> 14 ) } 15 </Fragment> 16) 17export default compose( 18 withComponentStore({ 19 data: DataStore, 20 }), 21 inject('dataStore'), 22 observer, 23)(DataHandler)
We provide some options that you can modify your stores after it is initialized.
onInitialized
is a function which is executed when the initialization of stores is complete.
1import React from 'react' 2import { inject, observer } from 'mobx-react' 3import { compose } from 'recompose' 4import { withComponentStore } from 'with-mobx-store' 5import DataItem from './DataItem' 6import DataStore from './stores/DataStore' 7const DataHandler = ({ data }) => ( 8 <Fragment> 9 { dataStore.data.map(datum => ( 10 <DataItem 11 key={datum.id} 12 {...datum} 13 /> 14 ) } 15 </Fragment> 16) 17export default compose( 18 withComponentStore({ 19 data: DataStore, 20 }, { 21 onInitialized: (stores) => { 22 stores.data.fetchData('https://api.example.com/sample') 23 }, 24 }), 25 inject('dataStore'), 26 observer, 27)(DataHandler)
onMounted
is executed when the component is mounted.
onUnMounted
is executed when the component is unmounted.
(C) 2017 Wongnai Media Co, Ltd.
with-mobx-store is licensed under MIT License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
project is archived
Details
Reason
Found 1/11 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
Reason
151 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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