-
-
Save lucianomlima/ed68b947823d431266697465daa5c2b6 to your computer and use it in GitHub Desktop.
React Cakes example component
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
import React from 'react'; | |
import { Link } from 'react-router-dom'; | |
import api from './Api'; | |
class Cakes extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
data: null, | |
slug: props.match.params.slug | |
}; | |
} | |
componentWillMount(){ | |
api.loadCategories() | |
.then((res) => { | |
return res.data.filter((item) => item.slug === this.state.slug) | |
}).then((data) => { | |
this.setState({ data }); | |
}); | |
} | |
render() { | |
if (this.state.data === null) { | |
return ( | |
<div>Carregando...</<div> | |
); | |
} | |
return ( | |
<div> | |
{this.state.data} | |
</div> | |
); | |
} | |
} | |
export default Cakes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment