Use React with Other Libraries

You don't have to go full React. The component lifecycle events, especially componentDidMount and componentDidUpdate, are good places to put your other libraries' logic.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var App = React.createClass({
  getInitialState: function() {
    return {myModel: new myBackboneModel({items: [1, 2, 3]})};
  },
 
  componentDidMount: function() {
    $(this.refs.placeholder).append($('<span />'));
  },
 
  componentWillUnmount: function() {
    // Clean up work here.
  },
 
  shouldComponentUpdate: function() {
    // Let's just never update this component again.
    return false;
  },
 
  render: function() {
    return <div ref="placeholder"/>;
  }
});
 
ReactDOM.render(<App />, mountNode);

You can attach your own event listeners and even event streams this way.

doc_React
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.