title: Adding/removing css classes to react components
body: <p>I have a react component for pagination called 'Pager', depending on the number of results and the size of the page it calculates the number of pages to display, and then, when clicking on a link, it fetchs the results for that page. In my case, I'm having problem on adding/removing the css class dinamically when a user click on a link. When the page is rendered the first time only the number '1' has to be 'active', but then when the user clicks on the link '2', '3', etc I need to remove the className attribute for the previous active link and add it to the clicked link.</p>
  
  <p>Any ideas on how to achieve that?</p>
  
  <p>My code looks like:</p>
  
  <pre><code>export class Pager extends React.Component {
  
  
  constructor() {
      super();
  }
  
  
  handleClick(i){
      console.log('Clicked on'+i);
      this.props.dispatch(modelActionsCreator.findModelsByProductType(this.props.productType,i));
  }
  
  render() {
      console.log(this.props.numPages);
      let links = [];
  
  
      for (let i = 1; i &lt;= this.props.numPages; i++) {
          links.push(&lt;li key={i} className={i==1?'active':''}&gt;&lt;a href="#" onClick={(e)=&gt;{
          e.preventDefault();
          this.handleClick(i);
          }}&gt;{i}&lt;/a&gt;&lt;/li&gt;);
      }
  
  
      return (&lt;ul className="pagination"&gt;
          &lt;li className="prev-page"&gt;&lt;a className="icon-arrow-left" href="#"&gt;&lt;/a&gt;&lt;/li&gt;
          {
              links.map((item)=&gt; {
                  return item;
              })
          }
          &lt;li className="next-page"&gt;&lt;a className="icon-arrow-right" href="#"&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;);
  
  
  }
  </code></pre>