From ebf24594e4fa9ea42ac24bdf1aa15823da1231f9 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 28 Feb 2018 12:03:58 -0500 Subject: [PATCH] Update 01 - Stateful Functions.js Add `interface S` for the type of state --- 07 - Returning State/01 - Stateful Functions.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/07 - Returning State/01 - Stateful Functions.js b/07 - Returning State/01 - Stateful Functions.js index d37126b..e7aa5f3 100644 --- a/07 - Returning State/01 - Stateful Functions.js +++ b/07 - Returning State/01 - Stateful Functions.js @@ -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 }; @@ -30,7 +34,7 @@ function handleClick(props, state, event) { // ); // }; // } -export function Counter(props : P, state) { +export function Counter(props: P, state: S) { return (
Clicked {state ? state.count : 0} times