React Native:指定的子元素已经有一个父级。

5
我有两个组件,DraggableCard和ChooseMachine(ChooseMachine使用DraggableCard)。当我到达ChooseMachine组件时,它返回错误:The specified child already has a parent. You must call removeView() on the child's parent first. 我不知道哪个子组件被调用了两次。
我已经尝试删除作为prop传递给DraggableCard的Some Text,这解决了错误,但DraggableCard不显示,而且这不是我需要的。它应该显示DraggableCard和传递的文本。我已经尝试将Some Text放在标记周围,但问题仍然存在。
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>
    )
  }
}

可拖动卡片组件

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>
    )
  }
}

我希望在"选择机器"组件上呈现可拖动卡片的效果。
1个回答

11

1
太好了!问题一直都在于我打开了MapView标签,而在这种情况下应该是自闭合的。 - Ernanni
上帝保佑你,伙计! - spatak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接