question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListView selection executes twice, both badly

See original GitHub issue

Category

[ ] Enhancement

[X] Bug

[ ] Question

Version

1.0.0-beta.6

Expected / Desired Behavior / Question

I have a ListView component that is set like this:

<ListView
          items={this.state.reactListItems}
          compact={true}
          viewFields={viewFields}
          selectionMode={SelectionMode.single}
          selection={ (e) => this.setState({
            showPanel: true,
            panelInfo: JSON.stringify(e)
          })} />

In the selection area I have set a state update using local fat arrow to pass the this object, which I want to use in a panel (or modal or whatever).

My issue is that this code will execute twice; once where it passes the output from the selection but does not update the state, then again where it updates the state, but now it does not pass the selection.

So in the code above, the value is ultimately [] on this.state.panelInfo.

Observed Behavior

I expected the item value and the state update to execute once with the values passed from the selected item.

Steps to Reproduce

The code above should be sufficient to repro.

I also tried using this function for debugging:

public _getSelection(item: any, ctx: any) {
    console.log('Selected items:', item);
    ctx.setState({
      showPanel: true,
      panelInfo: JSON.stringify(item)
    });
    console.log(ctx.state);
  }

Thanks for any suggestions on how to proceed!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AJIXuMuKcommented, Feb 11, 2021

It’s a closed thread.

Please, create new issue if you want us to pay attention to it.

Thank you!

0reactions
jaxnzcommented, Feb 11, 2021

Same issue on v2.4.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

ListView selection executes twice, both badly #11 - GitHub
As a workaround, I check in the _getSelection function whether item has a length that is not 0 before changing state, which works....
Read more >
Why does the `ItemSelected` method execute twice when ...
No, the only way to deselect an item is to set SelectedItem to null. When no item is selected, ItemSelected is also fired...
Read more >
vb.net - avoid list view selected index changed firing twice
Quite a simple question, when the selected index of a list view is changed, the event fires twice, once for deselection and a...
Read more >
ListView OnItemSelectionChanged fires multiple times when ...
The selection is always single at the clicked item. But once I begin scrolling up and down, the entries that enter the visible...
Read more >
Page Editor Consistency Errors | Mendix Documentation
Open the list view's properties > Data source and select an entity in the Entity (path) field; Change the type of the data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found