Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Categories extends React.Component {
- state = { categories: [], toggleEditCat: false, }
- componentDidMount() {
- axios.get(`/api/menus/${this.props.menuId}/categories`)
- .then( res => {
- this.setState({ categories:res.data })
- })
- }
- componentDidUpdate() {
- this.render()
- }
- editCategory = (name, description, id) => {
- const category = { name, description}
- axios.put(`/api/menus/${this.props.menuId}/categories/${id}`, {
- category })
- axios.get(`/api/menus/${this.props.menuId}/categories`)
- .then(res => {
- this.setState({ categories: res.data }, () =>
- console.log(this.state.categories))
- })
- }
- }
- render () {
- return (
- <Segment>
- <div>
- return this.state.categories.map(c => {
- return (
- <ul key={c.id}>
- <h3>Category Name: {c.name}</h3>
- </ul>
- )
- </div>
- </Segment>
- )
- }
Add Comment
Please, Sign In to add comment