React: leave the contents of a component alone

前端 未结 2 745
感情败类
感情败类 2020-12-31 21:45

Is it possible to have React ignore a subtree? i.e., don\'t compare or update it?

My use case is migrating to React. Re-writing all our Handlebars templates at once

2条回答
  •  猫巷女王i
    2020-12-31 22:29

    Have a look at this module. Simple and very effective. https://gist.github.com/alexeisavca/d4ff175fd16c93c8785d

    Here's a coffeescript version of it.

    module.exports = ReactIgnore = React.createClass
      shouldComponentUpdate: ->
        false
      render: ->
        React.Children.only @props.children
    

    And wrap your component in it:

    
      YourComponent
    
    

提交回复
热议问题