|
1 | 1 | import * as React from "react";
|
| 2 | +import { useState, useEffect } from "react"; |
2 | 3 | import { RNSStyle } from "react-nativescript";
|
3 | 4 | import { Color } from "@nativescript/core";
|
4 | 5 |
|
5 | 6 | export class GameLoop {
|
6 | 7 | private readonly subscribers = [];
|
7 |
| - private loopID: number|null = null; |
| 8 | + private loopID: NodeJS.Timeout|null = null; |
8 | 9 |
|
9 | 10 | constructor(private readonly frameRateMs: number = 1000 / 60){
|
10 | 11 | this.loop = this.loop.bind(this);
|
@@ -158,7 +159,7 @@ export class Marquee extends React.Component<{ text: string }, { index: number }
|
158 | 159 | // ),
|
159 | 160 |
|
160 | 161 | export class Clock extends React.Component<{}, { date: Date }> {
|
161 |
| - private timerID!: number; |
| 162 | + private timerID!: NodeJS.Timeout; |
162 | 163 |
|
163 | 164 | constructor(props) {
|
164 | 165 | super(props);
|
@@ -207,6 +208,44 @@ export class Clock extends React.Component<{}, { date: Date }> {
|
207 | 208 | }
|
208 | 209 | }
|
209 | 210 |
|
| 211 | +export function ClockFC(){ |
| 212 | + const [date, setDate] = useState(new Date()); |
| 213 | + |
| 214 | + useEffect(() => { |
| 215 | + const interval = setInterval(() => { |
| 216 | + setDate(new Date()); |
| 217 | + }, 1000); |
| 218 | + |
| 219 | + return () => { |
| 220 | + clearInterval(interval); |
| 221 | + }; |
| 222 | + }, []); |
| 223 | + |
| 224 | + return <textView>{date.toLocaleTimeString()}</textView>; |
| 225 | +} |
| 226 | + |
| 227 | +export function Counter(){ |
| 228 | + const [count, setCount] = useState(0); |
| 229 | + |
| 230 | + return ( |
| 231 | + <> |
| 232 | + <label>{count}</label> |
| 233 | + <button |
| 234 | + onTap={(eventData) => { |
| 235 | + setCount((currentCount: number) => { |
| 236 | + const nextCount = currentCount + 1; |
| 237 | + console.log(`Increasing count from ${currentCount} -> ${nextCount}`); |
| 238 | + |
| 239 | + return nextCount; |
| 240 | + }); |
| 241 | + }} |
| 242 | + > |
| 243 | + Increment |
| 244 | + </button> |
| 245 | + </> |
| 246 | + ); |
| 247 | +} |
| 248 | + |
210 | 249 | export class GameLoopTest extends React.Component<{}, {}> {
|
211 | 250 | render(){
|
212 | 251 | return React.createElement(
|
|
0 commit comments