react-dc-js icon indicating copy to clipboard operation
react-dc-js copied to clipboard

Prevent re-rendering when chart props remain the same

Open plourenco opened this issue 5 years ago • 0 comments

The props of a chart are set as dependencies of the useChart hook and shallow checked, causing them to be considered different in every side-effect. The following test represents the problem:

it('should not cause a re-render if props did not change', () => {
    const chartFunc = chartMock()
    chartFunc.foo = jest.fn()
    const Chart = BaseChart(() => chartFunc, [baseMixin])
    const { rerender } = render(<Chart foo="bar" />)
    expect(chartFunc.foo).toHaveBeenCalledTimes(1)
    rerender(<Chart foo="bar" />)
    expect(chartFunc.foo).toHaveBeenCalledTimes(1)
})

plourenco avatar Oct 20 '20 22:10 plourenco