-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyNumber.js
44 lines (41 loc) · 953 Bytes
/
MyNumber.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
36
37
38
39
40
41
42
43
44
import PropTypes from 'prop-types';
import React from 'react';
import { StyleSheet, Text } from 'react-native';
import { formatNumber } from './helperFunctions';
const MyComponent = ({
value,
decimalsToShow,
styles,
rest
}) => {
const txtStyle = styles !== undefined ? styles : defaultStyles.text;
const output = formatNumber(
value,
decimalsToShow === undefined ? 2 : decimalsToShow
);
return (
<>
<Text style={txtStyle} {...rest}>{output}</Text>
</>
);
};
const defaultStyles = StyleSheet.create({
text: {
color: '#000',
marginBottom: 4,
marginRight: 10
}
});
MyComponent.propTypes = {
value: PropTypes.number.isRequired,
decimalsToShow: PropTypes.number,
styles: PropTypes.instanceOf(Object),
rest: PropTypes.instanceOf(Object)
};
MyComponent.defaultProps ={
styles: undefined,
decimalsToShow: 0,
rest: {}
};
const MyNumber = React.memo(MyComponent);
export default MyNumber;