Skip to content

Instantly share code, notes, and snippets.

@lucianomlima
Forked from tosipaulo/react.js
Last active April 7, 2018 22:20
Show Gist options
  • Save lucianomlima/ed68b947823d431266697465daa5c2b6 to your computer and use it in GitHub Desktop.
Save lucianomlima/ed68b947823d431266697465daa5c2b6 to your computer and use it in GitHub Desktop.
React Cakes example component
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