All Projects → dobjs → dob-react

dobjs / dob-react

Licence: MIT License
React bindings for dob

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to dob-react

React Redux Firebase
Redux bindings for Firebase. Includes React Hooks and Higher Order Components.
Stars: ✭ 2,492 (+6635.14%)
Mutual labels:  react-bindings

dob-react · CircleCI Status npm version code coverage

React bindings for dob.

Design idea from Mobx Implementation

Install

npm i dob-react

Online demo

Here is a basic demo, and here is a demo with fractal.

Simple Usage

import { Provider, Connect } from 'dob-react'

@Connect
class App extends React.Component <any, any> {
    render() {
        return (
            <span>{this.props.store.name}</span>
        )
    }
}

ReactDOM.render(
    <Provider store={{ name: 'bob' }}>
        <App />
    </Provider>
, document.getElementById('react-dom'))

Connect: All parameters from outer Provider are injected into the wrapped components, and the component rerender when the variables used in the render function are modified(sync usage).

Connect all functions

Connect all

Connect all from Provider's parameters, also is this example above.

Connect extra data

Will also inject all parameters from outer Provider.

@Connect({
    customStore: {
        name: 'lucy'
    }
})
class App extends React.Component <any, any> {}

Map state to props

Will also inject all parameters from outer Provider.

@Connect(state => {
    return {
        customName: 'custom' + state.store.name
    }
})
class App extends React.Component <any, any> {}

ReactDOM.render(
    <Provider store={{ name: 'bob' }}> <App /> </Provider>
, document.getElementById('react-dom'))

Support stateless component

class App extends React.Component <any, any> {
    render() {
        return (
            <span>{this.props.store.name}</span>
        )
    }
}

const ConnectApp = Connect()(App)
// const ConnectApp = Connect({ ... })(App)
// const ConnectApp = Connect( state => { ... })(App)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].