BenCook28
BenCook28

Reputation: 129

React Native Moment Error: Expected a component class, got [object Object]

I read at least eight Stack Overflow posts about the error in the title, but I haven't yet resolved the issue since I capitalized everything in <>s and don't use HTML tags. Using Moment documentation as a guide, I'm trying to display the current day of the week in the first <Moment></Moment> and a date like October 9th, 2017 in the second. Below I pasted my App.js. I used create-react-native app to get started. What should I do instead?

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Moment from 'react-moment';


export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Moment format="dddd"></Moment>
        <Moment format='MMMM Do YYYY'></Moment>
        <Text>Today at a Glance</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
  },
});

Upvotes: 1

Views: 741

Answers (1)

rmovieira
rmovieira

Reputation: 36

I have the same issue and I found this in doc: <Moment element={Text} >1976-04-19T12:59-0500</Moment>

We need to to pass the element. The error message don't help, but doing this it works for me

doc link: https://github.com/headzoo/react-moment#usage-with-react-native

Upvotes: 2

Related Questions