title: React state value is not retained when value is set using useState within useEffect with dep []
body: <p>I am using Fluent UI Details List and trying to make row editable on icon click.
  My code is as below. On first run, it shows grid with empty data. Then it goes to useEffect (I tried both useEffect and useLayoutEffect, same behaviour) and data is fetched and stored in state. It also fires the render and the grid shows all the rows per the data. All good so far.
  When row &gt; cell 1 is double-clicked on the grid, I turned the row to editable mode. That is also working.</p>
  <p>For each editable column, I have a different onChange event attached. So, when any input text box/dropdown cell value changes, it fires the respective onChange event callback function.</p>
  <p>Within this cell change callback event, it gets item id and final changed value as input aurguments. And using them, data array will be updated and stored in state. This is my expectation.</p>
  <p>But when I read the current data array from state within the callback function, it is empty.</p>
  <p>So, basically, problem is that state value stored from useEffect is not retained.
  There is no other code line where data array state is updated. So, no chance that the data array is reset by code.
  If anyone has any idea or faced, solved such issue, let me know. Thanks in advance.</p>
  <hr />
  <p>Adding few things which I tried,</p>
  <ol>
  <li>I tried using the class component and it worked. only difference is that instead of useEffect, I used componentDidMount and instead of useState, I used this.setState. Not sure what is other difference within class and function component?
  The same code works in class component but not in function component.</li>
  <li>I tried using the same function component and instead of async call within useEffect, I made direct sync fetch call before render and loaded data in state as initial value. Then, it worked.
  So, it fails only when the data is fetched async mode within useEffect and set to state from there.</li>
  </ol>
  <p>My problem is resolved after converting to class component.
  but want to understand what is the issue within my function component code.</p>
  <pre><code>/** function component */
  const [dataItems, setDataItems] = useState&lt;IScriptStep[]&gt;([]);
  const [groups, setGroups] = useState&lt;IGroup[]&gt;([]);
  /** Component Did Mount */
    useLayoutEffect(() =&gt; {
      props.telemetry.log(`useEffect - []`, LogLevel.Debug);
      (async () =&gt; {
        let scriptSteps = await props.dataHelper.retrieveScriptSteps();
        setDataItems(scriptSteps);
        let groups = getGroups(scriptSteps);
        setGroups(groups);
        props.telemetry.log(`Data updated in state`, LogLevel.Debug);
      })();
    }, []);
  /** Render */
    return (
      &lt;div className=&quot;SubgridMain&quot;&gt;
        {props.telemetry.log(`render`, LogLevel.Debug)}
        &lt;div className=&quot;List&quot;&gt;
          &lt;DetailsList
            componentRef={_root}
            items={dataItems}
            groups={groups}
            columns={columns}
            ariaLabelForSelectAllCheckbox=&quot;Toggle selection for all items&quot;
            ariaLabelForSelectionColumn=&quot;Toggle selection&quot;
            checkButtonAriaLabel=&quot;select row&quot;
            checkButtonGroupAriaLabel=&quot;select section&quot;
            onRenderDetailsHeader={_onRenderDetailsHeader}
            onRenderRow={_onRenderRow}
            groupProps={{ showEmptyGroups: true }}
            onRenderItemColumn={_onRenderItemColumn}
            onItemInvoked={_onItemInvoked}
            compact={false}
          /&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    );
  /** on change cell value callback function */
  const _onChangeCellName = (entityId : string, fieldName:string, finalValue:string) =&gt; {
      let currentItems = dataItems;
      // create new data array
      let toUpdateState: boolean = false;
      let newItems = currentItems.map((item) =&gt; {
        if (item.key === entityId) {
          if (item.name !== finalValue) {
            toUpdateState = true;
            item.name = finalValue ?? null;
          }
        }
        return item;
      });
      if (toUpdateState) setDataItems(newItems);
    };
  /** columns configuration is set as below */
      let columns : IColumn[] = [
      {
          key: 'name',
          name: 'Name',
          fieldName: 'name',
          minWidth: 300,
          isResizable: true,
          onRender: this._onRenderCellName,
      },
      ..
      ..
      ]
  /** Render Name cell */ 
      private _onRenderCellName(item?: IScriptStep, index?: number, column?: IColumn) {
          if (item) {
              let stepName = item?.name ?? '';
              if (item.isEditable) {
                  let propsNameTextEditor: ITextEditorWrapperProps = {
                      entityId: item.key,
                      fieldName: 'name',
                      initialText: stepName,
                      multiline: true,
                      required: true,
                      setFinalValue: this._onChangeCellName,
                  };
                  return &lt;TextEditorWrapper {...propsNameTextEditor} /&gt;;
              } else {
                  return (
                      &lt;div className=&quot;ReadOnly&quot;&gt;
                          &lt;p&gt;{stepName}&lt;/p&gt;
                      &lt;/div&gt;
                  );
              }
          } else return &lt;&gt;&lt;/&gt;;
      };
  </code></pre>