Skip to content

polovi/react-baobab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-baobab

JS decorators for Baobab based on baobab-react.

Install

$ npm install --save react-baobab

Usage

state.js

import Baobab from 'baobab'

const tree = new Baobab({
  colors: ['red', 'green', 'blue']
});

export default tree;

customComponent.js

import React, {Component} from 'react'
import {branch} from 'react-baobab'

function addColor(tree, color) {
  tree.select('colors').push(color);
}

@branch({
  colors: ['colors']
})
class CustomComponent extends Component {
  componentDidMount() {
    console.log(this.props.colors); // return ['red', 'green', 'blue']
    this.props.dispatch(addColor, 'orange'); // dispatch action addColor with new color
  }

  ...
}

app.js

import React, {Component} from 'react'
import {root} from 'react-baobab'
import tree from './state'
import CustomComponent from './customComponent'

@root(tree)
class CustomComponent extends Component {
  
  ...
}

License

Released under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published