Yomguithereal / baobab-react

React integration for Baobab.
MIT License
310 stars 38 forks source link

this.state is null #116

Closed 222xiaohuan closed 7 years ago

222xiaohuan commented 8 years ago

Hi,

I wrote the demo according to the docs, but for some reason, it keeps give me the error, this.state is always null. attach my codes here:

index package pokedex state tree

Any help will be appreciate , thanks very much!

222xiaohuan commented 8 years ago

@Yomguithereal can you please help, thank you very much.

psypersky commented 8 years ago

Same problem here

psypersky commented 8 years ago

@222xiaohuan Change class SomeClass extends Component to React.createClass, still no sure exactly what is the difference or what is causing the problem, anyone has an idea?

psypersky commented 8 years ago

Got it! No Mixins Unfortunately ES6 launched without any mixin support. Therefore, there is no support for mixins when you use React with ES6 classes. Instead, we're working on making it easier to support such use cases without resorting to mixins. https://facebook.github.io/react/docs/reusable-components.html#no-mixins

222xiaohuan commented 8 years ago

@psypersky so that means we can't use this baobab-react in ES6 environment?or is there any solutions? thank you so much~ 👍

psypersky commented 8 years ago

Sure, use higher order components or decorators https://github.com/Yomguithereal/baobab-react/blob/master/docs/higher-order.md

Im using decorators with the babel-plugin-transform-decorators-legacy

@branch({
  chat: ['chat'],
})

export default class Chat extends React.Component {

  static propTypes = {
    chat: React.PropTypes.object.isRequired,
  }...
Yomguithereal commented 7 years ago

@psypersky is right. If you want to use ES6 classes or pure function components, you can use the HOC or the decorators.