首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >React Native:指定的子级已有父级

React Native:指定的子级已有父级
EN

Stack Overflow用户
提问于 2019-06-05 01:32:28
回答 1查看 5.1K关注 0票数 2

我有两个组件,DraggableCard和ChooseMachine (ChooseMachine使用DraggableCard)。当我到达ChooseMachine组件时,它会返回错误:The specified child already has a parent. You must call removeView() on the child's parent first.

我不知道被调用了两次的子组件是什么。

我尝试删除作为道具传递给DraggableCard的Some Text,它解决了这个错误,但DraggableCard没有显示,这并不是我真正需要的。它应该显示DraggableCard和传递的文本。我已经尝试将Some Text放在标签周围,但问题仍然存在。

代码语言:javascript
复制
import React, {Component} from 'react'
import {View} from 'react-native'
import MapView from 'react-native-maps'

import styles from './style'
import DraggableCard from '../../components/DraggableCard'

export default class ChooseMachine extends Component{

  render(){
    return(
      <View style={styles.body}>
        <MapView
          style={styles.map}>

          <DraggableCard>
            Some Text
          </DraggableCard>

        </MapView>

      </View>
    )
  }
}

DraggableCard组件

代码语言:javascript
复制
import React, {Component} from 'react'
import { View, Text } from 'react-native'

export default class DraggableCard extends Component {

  render(){

    return(
      <View
        style={styles.containerStyle}>
        <View style={styles.smallHyphen}/>
        <Text>
          {this.props.children}
        </Text>
      </View>
    )
  }
}

我希望在ChooseMachine组件上呈现DraggableCard

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-05 05:39:37

我猜你是在Android上看到的吧?试试下面的;https://github.com/react-native-community/react-native-maps/issues/1901

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56448778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档