SHARE
TWEET

Untitled

a guest Jan 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Categories extends React.Component {
  2.  state = { categories: [], toggleEditCat: false,  }
  3.  
  4.   componentDidMount() {
  5.    axios.get(`/api/menus/${this.props.menuId}/categories`)
  6.      .then( res => {
  7.      this.setState({ categories:res.data })
  8.     })
  9.   }
  10.  
  11. componentDidUpdate() {
  12.   this.render()
  13. }
  14.  
  15. editCategory = (name, description, id) => {
  16.  const category = { name, description}
  17.  axios.put(`/api/menus/${this.props.menuId}/categories/${id}`, {
  18.  category })
  19.  
  20.  axios.get(`/api/menus/${this.props.menuId}/categories`)
  21.   .then(res => {
  22.    this.setState({ categories: res.data }, () =>
  23.    console.log(this.state.categories))
  24.  })
  25. }  
  26.  
  27. }
  28.  
  29. render () {
  30.  return (
  31.   <Segment>
  32.     <div>
  33.       return this.state.categories.map(c => {
  34.       return (
  35.        <ul key={c.id}>
  36.         <h3>Category Name: {c.name}</h3>
  37.        </ul>
  38.       )
  39.     </div>
  40.   </Segment>
  41.  )
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top