Skip to content

Commit

Permalink
useState hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lugithub committed Feb 10, 2019
1 parent b4e2861 commit 9a9d6b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.css";

import { Hello, Helloc } from "./ms-starter";
import { Hello, Helloc, Helloh } from "./ms-starter";

interface AppProp {
title: string;
Expand All @@ -26,6 +26,7 @@ class App extends Component<AppProp> {
</header>
<Hello name="foo" enthusiasmLevel={3} />
<Helloc name="bar" />
<Helloh name="hooks" />
</div>
);
}
Expand Down
24 changes: 24 additions & 0 deletions src/ms-starter/components/hello-h.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useState } from "react";

import { HelloProps, getExclamationMarks } from "./hello";

export function Helloh({ name }: HelloProps) {
const [{ enthusiasmLevel }, setState] = useState({
enthusiasmLevel: 1
});

function handleClick() {
setState(prevS => {
return {
enthusiasmLevel: prevS.enthusiasmLevel + 1
};
});
}
return (
<div className="hello" onClick={handleClick}>
<div className="greeting">
Hello {name + getExclamationMarks(enthusiasmLevel)}
</div>
</div>
);
}
1 change: 1 addition & 0 deletions src/ms-starter/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./hello";
export * from "./hello-c";
export * from "./hello-h";

0 comments on commit 9a9d6b0

Please sign in to comment.