Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onEvents calls assigned function an increasingly larger amount of times when using setState #155

Closed
amomentunfolding opened this issue Mar 2, 2018 · 1 comment

Comments

@amomentunfolding
Copy link

Hi,
I'm working on a heatmap chart where the different items can be clicked to highlight other elements on the page.
I've run into some strange behaviour though where the onEvents function gets called an increasingly larger amount of times for every time the heatmap is clicked (2*number of clicks), which slows down the page and crashes it after a while.
This happens only when calling this.setState() within the function.
Relevant code below.

<ReactEcharts onEvents={{'click': (e) => { this.onHeatMapItemClick(e) }}}/>
onHeatMapItemClick = (heatmapObject) => {
        let tempList = Object.assign([], this.state.highlightedItems);
        let itemId = heatmapObject.data.id;

        if (!this.state.highlightedItems.includes(itemId)){
            tempList.push(itemId);
        }
        else {
            tempList.splice(tempList.indexOf(itemId), 1);
        }
        this.setState({highlightedItems: tempList});
        console.log("Executed");
    };

Console output:
echarts-itemclick

"echarts": "^4.0.2",
"echarts-for-react": "^2.0.7",
"react": "^16.2.0",

If anyone has any idea about what might be going on it would be appreciated
Cheers

@hustcc hustcc closed this as completed in 44c1e27 Mar 2, 2018
@hustcc
Copy link
Owner

hustcc commented Mar 2, 2018

Thanks, it is a typo. Fixed on the commit(44c1e27).

v2.0.8 published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants