I am currently facing an issue while using Moment.js and React Native to work with date and time. My code snippet below showcases how I am attempting to utilize the library.
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import * as moment from 'moment';
import { Card } from 'react-native-paper';
interface event {
title: string,
created: any,
expiration: any
}
const party : event = {
title: '21st Bday Party',
created: moment('2019 03 14'),
expiration: moment('2019 03 15')
}
export default function App() {
return (
<View style={styles.container}>
<Card>
<Text>{party.created.format()}</Text>
</Card>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
});
Upon running the code, I encounter the following error: TypeError: moment is not a function. Can someone please guide me on how to rectify this error?