简体   繁体   English

React Native没有初始化ReactCoundownClock

[英]React native not initializing ReactCoundownClock

Trying to run a simple example with the ReactCountdownClock. 尝试使用ReactCountdownClock运行一个简单的示例。 But it is not able to initialize. 但是它无法初始化。

The setup is as following: 设置如下:

 import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import {ReactCountdownClock} from 'react-countdown-clock'; export default class App extends React.Component { constructor() { super(); this.myCallback = this.myCallback.bind(this); } myCallback() { console.log("test"); } render() { return ( <View style={styles.container}> <ReactCountdownClock seconds={60} color="#000" alpha={0.9} size={300} onComplete={this.myCallback} /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> 

But I just keep getting an Element type is invalid: Expected a string (for built-in components) or a class/function (for composite components) but got: undefined. 但是我只是不断得到一个Element类型是无效的:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但是得到:未定义。 You likely forgot to export your component from the file its defined in. 您可能忘记了从定义其的文件中导出组件。

As far as I assume from the coffee-script code on the components Github page, you don't have to use the curly brackets on the import. 据我从组件Github页面上的coffee-script代码假设,您不必在导入中使用大括号。 So instead of using 所以不要使用

import { ReactContdownClock } from 'react-countdown-clock';

you could write 你可以写

import ReactContdownClock from 'react-countdown-clock';

cause there is just that single exported component. 因为只有一个导出的组件。

But as far as I understand React-Native you will run into a second issue because this component uses (renders) HTML Tags and these will not be displayed until they're rendered by a WebView. 但是据我所知,您将遇到第二个问题,因为该组件使用(渲染)HTML标记,并且这些标记只有在由WebView呈现后才会显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM