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

Provide hook to get changed props along with the internal chart object #40

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Check out [C3.js Reference](http://c3js.org/reference.html) for more details.
* className
* style
* unloadBeforeLoad
* onPropsChanged

## License

Expand Down
6 changes: 5 additions & 1 deletion react-c3js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
};
}
}]);
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class C3Chart extends React.Component {
className: PropTypes.string,
style: PropTypes.object,
unloadBeforeLoad: PropTypes.bool,
onPropsChanged: PropTypes.func,
};
}

Expand All @@ -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() {
Expand Down