Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Check for options change in ComponentWillReceiveProps #180

Open
wants to merge 1 commit into
base: chartjs-v2
Choose a base branch
from

Conversation

jgliner
Copy link

@jgliner jgliner commented Apr 19, 2017

Currently, options won't update along with the chart if new props are passed. This is especially an issue when updating charts dynamically (e.g. changing the yAxes label from a dropdown menu). There may be a slightly more elegant way to check for changes in user-defined options, but this check should not negatively affect performance.

@Jareechang
Copy link
Collaborator

hi @jgliner, would it possible to redraw when you update yAxes option on your side ?

(yAxesChanged 
   ? <LineChart redraw />
   : <LineChart />) 

I want to make sure we're minimizing regressions as we currently do not have any tests (will add some soon).

Please let me know if that works for you. Thanks

@Jareechang
Copy link
Collaborator

Hi @jgliner, sorry I mis-understood. I see what you are talking about.

If this is the case, I prefer that we use react's core utility for this case. Please see below for example.

npm i fbjs
var shallowEqual = require('fbjs/lib/shallowEqual');
var optsChange = !shallowEqual(nextProps.options, this.props.options);

Please update PR when you get a chance. Thank you.

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

Successfully merging this pull request may close these issues.

2 participants