-
Notifications
You must be signed in to change notification settings - Fork 96
Allow child components and give them access to chartist props #49
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
Conversation
fraserxu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
index.js
Outdated
| const { className, style, children, data, type } = this.props; | ||
| return ( | ||
| <div className={`ct-chart ${className || ''}`} ref='chart' style={style}> | ||
| {children && cloneElement(children, { type, data })} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you able to just use {this.props.children} or it's because you need to pass type and data down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! I had to use cloneElement to pass down the props to the children.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only used cloneElement method once when I have to passing props down to children with react-router, I've learned from others example it might be better to do a map function over the children in case user passing more than one child.
const children = React.Children.map(this.props.children, child => (
React.cloneElement(child, {
type,
data
})
))
return (
<div>{children}</div>
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that would work a lot better, especially if more plugins are added later.
|
Thanks @theslip , new version has published to v0.12.0 |
Added code to be compatible with react-chartist-plugin-accessibility.