2017-10-09 50 views
1

我至少讀了8篇關於標題錯誤的Stack Overflow帖子,但是我還沒有解決過這個問題,因爲我在<> s和不要使用HTML標籤。使用Moment文檔作爲指南,我試圖在第一個<Moment></Moment>和2017年10月9日的第一個日期中顯示當前的一週中的第幾天。下面我粘貼我的App.js.我使用了create-react-native應用程序來開始。我該怎麼做呢?React Native Moment Error:期望一個組件類,得到了[對象對象]

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', 
    }, 
}); 
+0

該組件的渲染,當你刪除下列行?: '<瞬間格式=「DDDD」> ' – 223seneca

+1

您正在給出一個格式,但不給格式化日期。 – bennygenel

+0

是的223seneca,當我註釋了組件呈現的那些行。另外,斯多葛學派的哲學搖滾! – BenCook28

回答

1

我有同樣的問題,我在DOC發現這一點: <Moment element={Text} >1976-04-19T12:59-0500</Moment>

我們需要傳遞的元素。該錯誤消息沒有幫助,但這樣做的工作對我來說

文檔鏈接: https://github.com/headzoo/react-moment#usage-with-react-native

+0

謝謝rmovieira!當我改變了我的渲染功能,下面,應用程序正確地呈現: – BenCook28

+0

渲染(){ 讓現在=新的日期(); 回報( <查看風格= {} styles.container> <矩元素= {文字}現在 今天在G長矛 ); } – BenCook28

相關問題