Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Update 01 - Stateful Functions.js #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 07 - Returning State/01 - Stateful Functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ interface P {
onClick: function;
}

interface S {
count: number;
}

// Callbacks take props and state as their first arguments. To update state,
// they simply return the new version of the state.
function handleClick(props, state, event) {
function handleClick(props: P, state: S, event) {
if (event.button === 1) {
// Middle click resets state to zero
return { count: 0 };
Expand All @@ -30,7 +34,7 @@ function handleClick(props, state, event) {
// );
// };
// }
export function Counter(props : P, state) {
export function Counter(props: P, state: S) {
return (
<div>
Clicked {state ? state.count : 0} times
Expand Down