1.12.0 • Published 1 year ago

react-mobx-store-container v1.12.0

Weekly downloads
65
License
MIT
Repository
github
Last release
1 year ago

react-mobx-store-container

Dynamic store to manage others stores (specialy usefull with react-loadable)

Use

Install StoreContainer

Create a StoreContainer in your main file to inject it in Provider tag (from mobx-react).

import * as React from 'react'
import { Provider } from 'mobx-react'
import { StoreContainer } from './lib/store-container'

export default class Bootstrap extends React.PureComponent<{}, {}> {
    private storeContainer: StoreContainer = new StoreContainer()

    render () {
        const stores = {
            container: this.storeContainer,
        }

        return (
            <Provider {...stores}>
                { /* ... */ }
            </Provider>
        )
    }
}

Important : The StoreContainer must be inject in Provider with name 'container'.

Use Dynamic Provider

Use DynamiProvider tag to provide Stores ifor children components. You have to use named stores. Add the store construction in factories attributes who will be use if the store does not exist in the StoreContainer.

import * as React from 'react'
import { DynamicProvider } from '../../lib/store-container'

// The store
import { WeatherStore } from './weather-store'

// The components who can access to the store
import Thermometer from './thermometer'
import HumiditySensor from './humidity-sensor'
import Nanometer from './nanometer'

export default class Home extends React.Component<{}, {}> {
    render () {
        return (
            <DynamicProvider names={['weather']} factories={{ weather: () => new WeatherStore() }}>
                <Thermometer />
                <HumiditySensor />
                <Nanometer />
            </DynamicProvider>
        )
    }
}
1.12.0

1 year ago

1.11.0

1 year ago

1.10.6

3 years ago

1.10.5

3 years ago

1.10.4

3 years ago

1.10.3

3 years ago

1.10.2

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago

1.0.0

4 years ago