Skip to content

Instantly share code, notes, and snippets.

@limscoder
Created November 20, 2017 19:48
Show Gist options
  • Save limscoder/4b1b452b487e16448b4285505f2ad332 to your computer and use it in GitHub Desktop.
Save limscoder/4b1b452b487e16448b4285505f2ad332 to your computer and use it in GitHub Desktop.
Component using props instead of state
type Hexagon = {
active: bool,
col: number,
row: number
};
type Props = {
hexData: Array<Hexagon>,
onClick: (Array<Hexagon>) => void
};
export default class Hexagons extends Component<Props> {
componentDidMount() {
this.hexGroup = d3.select(this.svg).append('g');
this.hexGroup.selectAll('.hex')
.data(this.props.hexData)
.enter()
.append('path')
...
.on('click', d => {
d3.event.preventDefault();
d3.event.stopPropagation();
this.props.onClick(this.props.hexData.map(hex => toggleHex(d, hex)));
})
}
render() {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment