magalhas / backbone-react-component

A bit of nifty glue that automatically plugs your Backbone models and collections into your React components, on the browser and server
http://magalhas.github.io/backbone-react-component/
MIT License
809 stars 72 forks source link

Not to run render twice collection.fetch #66

Closed RusAlex closed 9 years ago

RusAlex commented 9 years ago

I've simple React.Component and collection relation with your software.

I initialize empty collection, then try to fetch in in

componentDidMount() {
  this.getCollection().fetch({reset: true})
}

And your lib change state 3 times because two events fired in collection: request, reset, sync.

Sure I can do it like this:

    componentDidMount() {
      this.getCollection().fetch({
        reset: true,
        silent: true,
        success(collection) {
          collection.trigger('change');
        }
      });
    },

But please consider something, not to change state during collection fetch call so many times.

Or Am I doing something wrong ?

magalhas commented 9 years ago

The state changes many times because when the request starts there's a setState. There's another setState when the request ends. This allows you to render spinners and other things while the request is being done.

You can always set silent: true on as a fetch option to override this behaviour.

RusAlex commented 9 years ago

Ok I understand the idea.

Thanks for fast answering. Will try using your project further.

magalhas commented 9 years ago

Thank you for using this lib. Feel free to ask anything :+1: