title: How to generate file name on current datetime while download in react
body: <p>I am trying to generate the file name using current date time using below code:</p>
  
  <pre><code>getFileName() {
      let d = new Date();
      let dformat = [this.padLeft(d.getMonth() + 1),
      this.padLeft(d.getDate()),
      d.getFullYear()].join('') +
        '_' +
        [this.padLeft(d.getHours()),
        this.padLeft(d.getMinutes()),
        this.padLeft(d.getSeconds())].join('');
  
      console.log("getCurrentDate : ", dformat);
      return "GridWidget_" + dformat + ".csv";
    }
  
      render() {
  return(
      &lt;CSVLink data={data} filename={this.getFileName()} className="btn btn-primary" target="_blank"&gt;Export To CSV&lt;/CSVLink&gt;);
      }
  </code></pre>
  
  <p>Issue with the above code is like File name is not generated with date time while downloading the file, but the time is taken while the page loads. What I want to do is the filename should generated only when the user clicks the download button. </p>
  
  <p>I know this doesn't make much difference in time but requirement is like should generate it with actual date time. Not able to understand why this is happening.</p>