Skip to content

Instantly share code, notes, and snippets.

@JohnPhamous
Created February 16, 2019 18:36
Show Gist options
  • Select an option

  • Save JohnPhamous/bb068557c1c02732474054cfa71fca1e to your computer and use it in GitHub Desktop.

Select an option

Save JohnPhamous/bb068557c1c02732474054cfa71fca1e to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
export default class titles extends Component {
state = {
tiles: []
};
populateTiles = () => {
console.log("Get data");
const newData = [
{
title: "bobo",
note: "lorem ipsum"
},
{
title: "anna",
note: "lorem ipsum2"
}
];
this.setState({ tiles: newData });
};
render() {
return (
<div style={{ border: `1px solid red`, padding: `50px ` }}>
<button onClick={this.populateTiles}>Click Me</button>
{this.state.tiles.map(tile => (
<div>
<h1>{tile.title}</h1>
<p>{tile.note}</p>
</div>
))}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment