Skip to content

Commit 9f9d63e

Browse files
committed
Merge pull request react-dnd#175 from bebraw/docs-static
Document how to deal with static methods and properties
2 parents c879261 + f77c2f7 commit 9f9d63e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

docs/00 Quick Start/FAQ.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,89 @@ This is not currently documented, but you can take cues from the built-in [`HTML
223223

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

226+
### Why my static methods and properties won't work?
227+
228+
Consider example
229+
230+
```javascript
231+
var Page = React.createClass({
232+
mixins: [
233+
Router.State
234+
],
235+
236+
statics: {
237+
willTransitionTo: function(transition, params) {
238+
...
239+
},
240+
},
241+
242+
render: function() {
243+
...
244+
},
245+
});
246+
247+
module.exports = DragDropContext(HTML5Backend)(Page);
248+
```
249+
250+
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:
251+
252+
-------------------
253+
```javascript
254+
var Page = React.createClass({
255+
mixins: [
256+
Router.State
257+
],
258+
259+
render: function() {
260+
...
261+
},
262+
});
263+
264+
module.exports = DragDropContext(HTML5Backend)(Page);
265+
module.exports.willTransitionTo = function(transition, params) {
266+
...
267+
};
268+
```
269+
-------------------
270+
```javascript
271+
function statics(a) {
272+
return b => Object.assign(b, a)
273+
}
274+
275+
class Page {
276+
render() {
277+
...
278+
},
279+
})
280+
281+
export default statics({
282+
willTransitionTo(transition, params) {
283+
...
284+
}
285+
})(DragDropContext(HTML5Backend)(Page));
286+
```
287+
-------------------
288+
```javascript
289+
function statics(a) {
290+
return b => Object.assign(b, a)
291+
}
292+
293+
@statics({
294+
willTransitionTo(transition, params) {
295+
...
296+
}
297+
})
298+
@DragDropContext(HTML5Backend)
299+
class Page {
300+
render() {
301+
...
302+
},
303+
});
304+
305+
export default Page;
306+
```
307+
-------------------
308+
226309
## Meta
227310

228311
### Is this Dungeons & Dragons?

0 commit comments

Comments
 (0)