mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-07-12 15:18:34 +08:00
Rewrite of Day 1 to use modern React (#294)
* update to hooks * more class to function * cleanup * finish ts final * update html lesson * add lessons page * clean up * move getters into context * adding type * fix bug * step 5 cleanup * init final pass * text tweak * fix ternaries * readme cleanup * fixed root readme
This commit is contained in:
@@ -1,27 +1,14 @@
|
||||
import React from 'react';
|
||||
import { Button } from './Button';
|
||||
|
||||
export class Counter extends React.Component<any, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
clicks: 0
|
||||
};
|
||||
}
|
||||
render() {
|
||||
const { text } = this.props;
|
||||
const { clicks } = this.state;
|
||||
return (
|
||||
<div>
|
||||
{text}: {clicks}
|
||||
<Button onClick={this._onButtonClick}>Click</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
_onButtonClick = () => {
|
||||
this.setState({
|
||||
clicks: this.state.clicks + 1
|
||||
});
|
||||
};
|
||||
export const Counter = props => {
|
||||
const [clicks, setClicks] = React.useState(0);
|
||||
const handleClick = () => setClicks(clicks + 1);
|
||||
const { text } = props;
|
||||
return (
|
||||
<div>
|
||||
{text}: {clicks}
|
||||
<Button onClick={handleClick}>Click</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user