title: Make sure things run only once in componentDidUpdate() and componentDidMount()
body: <p>If I have a method that initialized something (like a jQuery widget), how can I make sure that the initialize gets called only once, but gets called for both refreshes and for when one navigates to that page without refresh. My current approach is the below:</p>
  
  <pre><code>//  key used to make sure initialize() only runs in one of DidUpdate/DidMount
  let key = 0;
  
  Component = React.createClass({
    mixins: [ReactMeteorData],
    hasKey() {
      return key;
    },
    getKey() {
      key = 1;
    },
    resetKey() {
      key = 0;
    },
    componentDidUpdate() {
      if (!(this.hasKey())) {
        initialize()();
        this.getKey();
      }
    },
    componentDidMount() {
      if (!(this.hasKey())) {
        initialize()();
        this.getKey();
      }
    },
    componentWillUnmount() {
      this.resetKey();
    }
  }})
  </code></pre>