React Table 7 - Expand Rows on Table Load

Solution 1:

Using a memoized array, instead of a state array mutated by useEffect, seems to work just fine (sandbox):

  const expandedRows = React.useMemo(() => {
    if (data?.data) {
      let arr = [{0: false}];
      let d = data.data;
      if (d.getGroupedSamplingStationBySystemId.length > 0) {
        arr = d.getGroupedSamplingStationBySystemId.map((sid, ind) => {
          return { [ind]: true };
        });
      }
      return arr;
    }
  }, []);