Added react example

This commit is contained in:
Micah Godbolt
2019-02-15 16:55:03 -08:00
parent a7abd33140
commit b90e710ba0
7 changed files with 306 additions and 25 deletions

View File

@@ -1,13 +1,13 @@
import React from 'react';
import { Counter } from './components/Counter';
export class App extends React.Component {
render() {
return (
<div>
</div>
<div>
<h2>My App</h2>
<Counter start={2} />
</div>
);
}
}

View File

@@ -0,0 +1,14 @@
.Button {
background: #0078d4;
color: white;
padding: 5px 10px;
outline: none;
border: none;
}
.Button:hover {
background: #005a9e;
}
.Button:active {
background: #004578;
}

View File

@@ -0,0 +1,10 @@
import React from 'react';
import './Button.css';
export const Button = props => {
return (
<button className="Button" onClick={props.onClick}>
{props.children}
</button>
);
};

View File

@@ -0,0 +1,25 @@
import React from 'react';
import { Button } from './Button';
export class Counter extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {
counter: props.start
};
}
render() {
return (
<div>
<span> {this.state.counter} </span>
<Button
onClick={() => {
this.setState({ counter: this.state.counter + 1 });
}}
>
Click Me
</Button>
</div>
);
}
}