React-Native:如何嵌套容器

时间:2018-04-08 13:50:44

标签: react-native

如何从其他容器构造容器。 例如:

  • containerA - 负责A
  • containerB - 负责B

容器C - 负责不同风格C的A + B.

代码:

class ContainerA extends Component{
    render() {
        return (
            <ComponentA/>
        )
    }
}


class ContainerB extends Component{
    render() {
        return (
            <ComponentB/>
        )
    }
}



class ContainerC extends Component{
    render() {
        return (
            <ContainerA/>
            <ContainerB/>
        )
    }
}

1 个答案:

答案 0 :(得分:1)

如果要在React Native中对组件进行分组,可以使用View

import React, { Component } from 'react'
import { View } from 'react-native'

import ContainerA from './ContainerA'
import ContainerB from './ContainerB'

class ContainerC extends Component{
    render() {
        return (
          <View style={styles.containerStyle}>
            <ContainerA/>
            <ContainerB/>
          </View>
        )
    }
} 

const styles = {
  containerStyle = {
    // ...
  }
}