From c9bc8405c60412f59977b6b7db62fd9822b9d029 Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Wed, 6 Jun 2018 11:16:22 +0200 Subject: [PATCH] Provide hook to get changed props along with the internal chart object This would allow consumers to interact with the internal chart, call C3 API methods when something changed such as show/hide bools, legend, formats, etc. (anything but chart data) --- README.md | 1 + react-c3js.js | 6 +++++- src/index.js | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2663b0..91a5d68 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Check out [C3.js Reference](http://c3js.org/reference.html) for more details. * className * style * unloadBeforeLoad +* onPropsChanged ## License diff --git a/react-c3js.js b/react-c3js.js index a90fbe1..f730ac7 100644 --- a/react-c3js.js +++ b/react-c3js.js @@ -47,6 +47,9 @@ var C3Chart = function (_React$Component) { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(newProps) { this.updateChart(newProps); + if (newProps.onPropsChanged) { + newProps.onPropsChanged(this.props, newProps, this.chart); + } } }, { key: 'componentWillUnmount', @@ -136,7 +139,8 @@ var C3Chart = function (_React$Component) { gauge: _propTypes2.default.object, className: _propTypes2.default.string, style: _propTypes2.default.object, - unloadBeforeLoad: _propTypes2.default.bool + unloadBeforeLoad: _propTypes2.default.bool, + onPropsChanged: _propTypes2.default.func }; } }]); diff --git a/src/index.js b/src/index.js index 5d08e65..36e590e 100644 --- a/src/index.js +++ b/src/index.js @@ -40,6 +40,7 @@ class C3Chart extends React.Component { className: PropTypes.string, style: PropTypes.object, unloadBeforeLoad: PropTypes.bool, + onPropsChanged: PropTypes.func, }; } @@ -50,6 +51,9 @@ class C3Chart extends React.Component { componentWillReceiveProps(newProps) { this.updateChart(newProps); + if (newProps.onPropsChanged) { + newProps.onPropsChanged(this.props, newProps, this.chart); + } } componentWillUnmount() {