Skip to content

Instantly share code, notes, and snippets.

@wesdeveloper
Created June 20, 2017 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesdeveloper/927cf48cd5c1027342bb6614f358f2e4 to your computer and use it in GitHub Desktop.
Save wesdeveloper/927cf48cd5c1027342bb6614f358f2e4 to your computer and use it in GitHub Desktop.
import React from 'react'
import ChipInput from 'material-ui-chip-input'
class Chip extends React.Component {
constructor(props) {
super(props)
this.state = {
chips: [],
limit: 3
}
}
handleAddChip (data) {
const chips = this.state.chips
if(this.state.chips.length <this.state.limit &&data.length < 5){
chips.push(data)
console.warn(chips)
this.setState({ chips })
}
}
handleDeleteChip (chip, index) {
const chips = this.state.chips
chips.splice(index, 1)
this.setState({ chips })
}
render() {
return(
<div>
<ChipInput
value={this.state.chips}
onRequestAdd={(chip) => this.handleAddChip(chip)}
onRequestDelete={(chip, index) => this.handleDeleteChip(chip, index)}
/>
</div>
)
}
}
export default Chip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment