Created
November 20, 2017 19:48
-
-
Save limscoder/4b1b452b487e16448b4285505f2ad332 to your computer and use it in GitHub Desktop.
Component using props instead of state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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