fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

[Bug]: DetailsList onColumnClick not getting updated state

Open elvenprogrammer opened this issue 2 years ago • 1 comments

Library

React / v8 (@fluentui/react)

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 9.95 GB / 31.73 GB
  Browsers:
    Edge: Spartan (44.22621.1265.0), Chromium (110.0.1587.49)
    Internet Explorer: 11.0.22621.1

Are you reporting Accessibility issue?

None

Reproduction

https://codepen.io/ElvenProgrammer/pen/poOEObr?editors=0011

Bug Description

Actual Behavior

During onColumnClick callback, current state is not reflected, even after using useCallback as suggested in some open threads. In the repro, when I click on the column header, in the console I get "undefined" for the "columns" state.

image

As documented also in: https://stackoverflow.com/questions/70894282/react-issue-with-fetching-and-updating-the-state-in-usecallback https://stackoverflow.com/questions/65183158/react-function-does-not-print-current-states

Expected Behavior

During onColumnClick callback I want to get the "columns" state so I can slice the array and update sorting metadata as in Fluent UI examples

Logs

"onColumnClick" // [object Array] (0)
[] undefined

Requested priority

High

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations

  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • [X] The provided reproduction is a minimal reproducible example of the bug.

elvenprogrammer avatar Feb 25 '23 15:02 elvenprogrammer

I can confirm I have the same problem as described. Tried different setups, tried useCallback. It does not work as expected.

I'm on spfx 1.17.2 and fluentui 7.199.1.

Moving back to using a class component instead of a functional component solved it for me.

martinlingstuyl avatar Jun 01 '23 10:06 martinlingstuyl

Because this issue has not had activity for over 180 days, we're automatically closing it for house-keeping purposes.

Still require assistance? Please, create a new issue with up-to date details.

confirmed still have the issue in latest version. @spmonahan Just checking is there any suggestions?

jarvan-jiang avatar Aug 08 '24 03:08 jarvan-jiang

The issue in the repro case is that onColumnClick and columns were memoized but did not have all the dependencies listed so they were stale when logged. Updating the dependencies appears to render the expected result: https://codepen.io/seanms/pen/RwzZjer

spmonahan avatar Aug 08 '24 15:08 spmonahan