Skip to content

Commit

Permalink
Document how to deal with static methods and properties
Browse files Browse the repository at this point in the history
  • Loading branch information
bebraw committed Jun 1, 2015
1 parent c4b71a5 commit f77c2f7
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions docs/00 Quick Start/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,89 @@ This is not currently documented, but you can take cues from the built-in [`HTML

React DnD requires React 0.13. Make sure you are using at least that version.

### Why my static methods and properties won't work?

Consider example

```javascript
var Page = React.createClass({
mixins: [
Router.State
],

statics: {
willTransitionTo: function(transition, params) {
...
},
},

render: function() {
...
},
});

module.exports = DragDropContext(HTML5Backend)(Page);
```

Even though a bit surprising `willTransitionTo` won't get triggered in this case! React DnD doesn't proxy static methods and properties as that is a problem that gets complex quite fast. Hence if you want to use static you should apply them before `DragDropContext` like this:

-------------------
```javascript
var Page = React.createClass({
mixins: [
Router.State
],

render: function() {
...
},
});

module.exports = DragDropContext(HTML5Backend)(Page);
module.exports.willTransitionTo = function(transition, params) {
...
};
```
-------------------
```javascript
function statics(a) {
return b => Object.assign(b, a)
}

class Page {
render() {
...
},
})

export default statics({
willTransitionTo(transition, params) {
...
}
})(DragDropContext(HTML5Backend)(Page));
```
-------------------
```javascript
function statics(a) {
return b => Object.assign(b, a)
}

@statics({
willTransitionTo(transition, params) {
...
}
})
@DragDropContext(HTML5Backend)
class Page {
render() {
...
},
});

export default Page;
```
-------------------

## Meta

### Is this Dungeons & Dragons?
Expand Down

0 comments on commit f77c2f7

Please sign in to comment.