我有两个组件,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
放在标签周围,但问题仍然存在。
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组件
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
发布于 2019-06-05 05:39:37
我猜你是在Android上看到的吧?试试下面的;https://github.com/react-native-community/react-native-maps/issues/1901
https://stackoverflow.com/questions/56448778
复制相似问题