-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
35 lines (28 loc) · 969 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { useMemo, useState } from 'react';
import { View, Text, Button } from "react-native";
function factorial(n) {
if (n < 0) {
return -1;
}
if (n === 0) {
return 1;
}
return n * factorial(n - 1);
}
const App = () => {
const [counter, setCounter] = useState(1);
const result = useMemo(() => {
console.log('calculate', counter);
return factorial(counter);
}, [counter]);
console.log('render', { counter });
return (
<View style={{flex:1, justifyContent:"center", backgroundColor:"#E9D5DA"}}>
<Text style={{fontSize:26, textAlign:"center"}}>FACTORIAL APP {'\n'}</Text>
<Text style={{fontSize:20, textAlign:"center"}}>Factorial of {counter} is: {result} {'\n'}</Text>
<Button color="#4D4C7D" title="MINUS" onPress={() => setCounter(counter - 1)}/>
<Button color="#827397" title="PLUS" onPress={() => setCounter(counter + 1)}/>
</View>
);
};
export default App;