I have a function that looks like this:
select(e) {
    let { selectedItems } = this.state;
    let arr: number[] = [];
    for (var i = 0; i < 2; i++) arr = [...arr, i];
    this.setState(
      {
        selectedItems: arr,
      }
    );
  console.log(selectedItems);
  }
But when I try to console.log(selectedItems), all I get is an empty array. When I console.log(arr), I get the correct output I'm looking for -- an array of length 2. What might be going on here and how can I assign selectedItems to the value of arr?