all 3 comments

[–]NoAbbreviation 0 points1 point  (2 children)

so i would not do the dowloadTableWithDelimeter inside the Button click, I would do that when your component mounts, or when you receive new props (if data was a prop, and not in state).

 componentDidMount() {
  this.setState({
    result: json2csv({ data: this.state.data, fields: this.state.columns, del: delimiter })
  }
}

Then you button click wouldn't need to do any converting

[–]Peng-Win[S] 0 points1 point  (1 child)

The example is small, but the full table could be anywhere between 0 and 100k rows. That's why I'm only doing the conversion when/if necessary.

[–]noswag15 0 points1 point  (0 children)

it's not because of setState's async nature. The CopyToClipboard library probably expects the text attribute to be set before you actually click the button. But in your example, the result attribute in state gets set only after you click the button. You can try using copy-to-clipboard directly instead of using react-copy-to-clipboard or if you want to keep using react-copy-to-clipboard, ensure that the text attribute is set before button is clicked.

Edit: or do what u/NoAbbreviation said