title: In a react class: How do I pass a variable inside same component
body: <p>I'm learning ReactJS and need to pass a variable inside the same component.</p>
  
  <p>Here's an example</p>
  
  <pre><code>var DataBase = [
      {
          position: 1
      },
      {
          position: 2
      },
      {
          position: 3
      },
      {
          position: 4
      }
  ];
  
  var Component = React.createClass({
  
      getDefaultProps: function() {
          var counter = 0;
      },
  
      componentDidMount: function() {
          var dbPos = this.props.db[counter+1].position;
          return dbPos;
      }, 
  
      render: function () {
           return (
              &lt;div className="Component"&gt;
                  {this.dbPos}
              &lt;/div&gt;
           ); 
      }
  });
  
  ReactDOM.render(
      &lt;Component db={DataBase} /&gt;,
      document.getElementById('main')
  );
  </code></pre>
  
  <p>So, this obviously doesn't work. What I need is to pass <code>var dbPos</code> created in <code>componentDidMount</code> to the <code>render</code> (without any events like onClick). This will be time driven, like 10 seconds in each position with setTimeout().</p>
  
  <p>Is this possible? How? Is there a better solution? I'll appreciate all your help.</p>