Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

Using Moment.js with React Native Typescript

$
0
0

I'm using Moment.js and React Native to display/manipulate date and time in the following fashion but can't quite seem to use it correctly. The code below demonstrates my usage of 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,  },});

I get the following error: TypeError: moment is not a function. What am I doing wrong? How can this issue be resolved?


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>