导入组件不起作用

时间:2017-04-21 05:17:40

标签: react-native

自定义组件

import React, { Component } from 'react'
import { Text } from 'react-native'
import { Content } from 'native-base'

export default class Login extends Component {
  render () {
    return (
      <Content>
        <Text>This is stateless Component</Text>
      </Content>
    )
  }
}

index.ios.js

import React, { Component } from 'react'
import { AppRegistry, Text, View } from 'react-native'
import { Container, Header, Title, Content } from 'native-base'
import Login from './src/components/Login'

export default class MyApp extends Component {
  render () {
    return (
      <Container>
        <Header>
          <Title>Login</Title>
        </Header>
        <Login />
      </Container>
    )
  }
}

AppRegistry.registerComponent('MyApp', () => MyApp)

仅在正在运行的应用中显示标题。预期This is stateless Component不存在。请问任何人都可以看一下吗?

1 个答案:

答案 0 :(得分:1)

您只能在容器组件中使用 native-base Content组件:

import React, { Component } from 'react'
import { Text } from 'react-native'
import { Container, Content } from 'native-base'

export default class Login extends Component {
    render () {
      return (
        <Container>
          <Content>
            <Text>This is stateless Component</Text>
          </Content>
        </Container>
     )
   }
}