Javascript 在react native中调用两个相同的子组件但只有一个在父组件中工作,为什么?

Javascript 在react native中调用两个相同的子组件但只有一个在父组件中工作,为什么?,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我从父组件调用两个相同的子组件。一个工作正常,另一个没有渲染,甚至没有调用我通过控制台检查的put。 这是我的父组件的代码 我在我的代码中调用NearbyList组件(它是父组件,我在这里调用我的子组件,您可以看到NearbyList仅第一个是调用,而不是下一个) 从“../../Uicomponents/NearByList/NearByList”导入NearByList 类RestaurantList扩展了组件{ 建造师(道具){ 超级(道具); 此.state={ favRest:null

我从父组件调用两个相同的子组件。一个工作正常,另一个没有渲染,甚至没有调用我通过控制台检查的put。 这是我的父组件的代码 我在我的代码中调用NearbyList组件(它是父组件,我在这里调用我的子组件,您可以看到NearbyList仅第一个是调用,而不是下一个)

从“../../Uicomponents/NearByList/NearByList”导入NearByList
类RestaurantList扩展了组件{
建造师(道具){
超级(道具);
此.state={
favRest:null,
selectedRest:null,
NearByRestarants:null,
加载:对,
SnacksLoading:this.props.SnacksLoading,
RestaurantLoading:this.props.RestLoading,
FetchRestaurantError:this.props.FetchRestaurantError,
fetchSnacksError:this.props.fetchSnacksError
};
这个.props.getNearbyrestaurants(50.8507855,4.3539655);
这个.props.getNearbySnacks(50.8507855,4.3539655);
}
组件willmount(){
设x=this.props.favList
if(x){
这是我的国家({
favRest:x
})
}
}
组件将接收道具(下一个){
console.log('sajhdgjahs',下一个)
如果(下一步,小吃){
这是我的国家({
小吃:下一个,小吃,
SnacksLoading:next.SnacksLoading,
fetchSnacksError:next.fetchSnacksError
});
}
如果(下一个favList){
this.setState({favRest:next.favList});
}
如果(下一个,附近){
这是我的国家({
附近的房地产商:下一个。附近,
RestaurantLoading:next.RestaurantLoading,
FetchRestaurantError:next.FetchRestaurantError
});
}
if(next.fetchRestaurantError){
this.setState({FetchRestaurantError:next.FetchRestaurantError})
}
}
render(){
返回(
{this.refs['DRAWER_REF'].closeDrawer();}
导航={this.props.navigation}/>}>
this.refs['DRAWER\u REF'].openDrawer()}导航=
{this.props.navigation}title={“餐厅”}/>
{this.props.addfav(this.props.User_id,id)}
removeFav={(id)=>{this.props.removeFav(this.props.User_id,id)}
加载={this.state.RestaurantLoading}
错误={this.state.FetchRestaurantError}
okok={'jshdjs'}
ListData={this.state.NearbyRestaurants}/>
{this.props.addfav(this.props.User_id,id)}
removeFav={(id)=>{this.props.removeFav(this.props.User_id,id)}
错误={this.state.fetchSnacksError}
ListData={this.state.snakts}/>
);
}
}
导出默认连接(
状态=>({
数据:state.common.get('data'),
附近:state.sign.get('NearbyRest'),
零食:state.sign.get(“零食”),
favList:state.common.get('favList'),
User\u id:state.sign.get('User\u id'),
重新加载:state.signin.get('RestLoading'),
FetchRestaurantError:state.signin.get('FetchRestaurantError'),
SnacksLoading:state.sign.get('SnacksLoading'),
fetchSnacksError:state.signin.get('fetchSnacksError')
}),
分派=>({
getData:data=>dispatch(Actions.common.getData(data)),
getUserData:data=>dispatch(Actions.main.getUserData(data)),
addfav:(用户,地点)=>dispatch(Actions.common.addfavorite(用户,
地点(,
removeFav:(用户,索引)=>dispatch(Actions.common.RemoveFavorite(用户,
索引(,
GetNearByRestarants:(纬度、经度)=>
调度(Actions.signin.GetNearByRestarants(纬度、经度)),
getNearbySnacks:(纬度、经度)=>
调度(Actions.signin.getNearbySnacks(纬度、经度)),
})
)(餐厅名单);

我觉得这不像是正确的javascript。而且,我相信这比产生问题所需的代码多得多。请看。@NieDzejkob我添加了父组件的完整代码请现在检查您添加了完整代码。伟大的现在我们需要你移除不相关的部分。@NieDzejkob现在检查一下
 import NearByList from "../../Uicomponents/NearbyLists/NearbyList"
 class RestaurantList extends Component {

   constructor(props) {
super(props);
this.state = {
  favRest:null,
  selectedRest: null,
  NearbyRestaurants: null,
  loading: true,
  SnacksLoading: this.props.SnacksLoading,
  RestaurantLoading: this.props.RestLoading,
  fetchRestaurantsError: this.props.fetchRestaurantsError,
  fetchSnacksError:this.props.fetchSnacksError
};
this.props.getNearbyrestaurants(50.8507855, 4.3539655);
this.props.getNearbySnacks(50.8507855, 4.3539655);
   }

   componentWillMount() {

let x= this.props.favList
if (x) {
  this.setState({
    favRest: x
  })
}
}

 componentWillReceiveProps(next) {
console.log('sajhdgjahs',next)
if (next.Snacks) {
  this.setState({
    Snacks: next.Snacks,
    SnacksLoading: next.SnacksLoading,
    fetchSnacksError: next.fetchSnacksError
  });
}
if (next.favList) {
    this.setState({ favRest: next.favList });
  }

if (next.Nearby) {
  this.setState({
    NearbyRestaurants: next.Nearby,
    RestaurantLoading: next.RestaurantLoading,
    fetchRestaurantsError: next.fetchRestaurantsError
  });
}
if (next.fetchRestaurantsError) {
  this.setState({ fetchRestaurantsError: next.fetchRestaurantsError })
}
}

render() {
return (
  <DrawerLayoutAndroid
  ref={'DRAWER_REF'}
  drawerWidth={250}
  drawerPosition={DrawerLayoutAndroid.positions.Left}
  renderNavigationView={() => <Sidebar  close={()=>      
 {this.refs['DRAWER_REF'].closeDrawer();}}
  navigation={this.props.navigation}/>}>
  <View style={{ flex: 1, backgroundColor: this.props.data.theme }}>
    <Header menu={()=>this.refs['DRAWER_REF'].openDrawer()} navigation= 
  {this.props.navigation} title={"Restaurants"} />
    <Container style={{backgroundColor:'black'}}>
    <Tabs  style={{backgroundColor:'black'}}>
    <Tab style={{backgroundColor:'black'}}
      heading={ 
      <TabHeading style={{backgroundColor:'black'}}>
      <Text style={{color:'white'}}>Restaurants</Text>
      </TabHeading>}>

      <NearByList 
      FavListofUser={this.state.favRest}
      address={'RestaurantDetail'}
      navigation={this.props.navigation}
      addfav={(id)=>{ this.props.addfav(this.props.User_id,id)}}
      removeFav={(id)=>{this.props.removeFav(this.props.User_id,id)}}
      loading={this.state.RestaurantLoading}
      error={this.state.fetchRestaurantsError}
      okok={'jshdjs'}
      ListData={this.state.NearbyRestaurants} />

      </Tab>
      <Tab style={{backgroundColor:'black'}}
       heading={
      <TabHeading style={{backgroundColor:'black'}}>
      <Text style={{color:'white'}}>Snacks</Text>
      </TabHeading>}>

      <NearByList 
      FavListofUser={this.state.favRest}
      navigation={this.props.navigation}
      loading={this.state.SnacksLoading}
      address={'SnackDetail'}
      addfav={(id)=>{ this.props.addfav(this.props.User_id,id)}}
      removeFav={(id)=>{this.props.removeFav(this.props.User_id,id)}}
      error={this.state.fetchSnacksError}
      ListData={this.state.Snacks} />

      </Tab>
    </Tabs>
    </Container>
   </View>
  </DrawerLayoutAndroid>
);
    }
  }

 export default connect(
   state => ({
     data: state.common.get('data'),
     Nearby: state.signin.get('NearbyRest'),
     Snacks: state.signin.get('Snacks'),
     favList: state.common.get('favList'),
     User_id: state.signin.get('User_id'),
     RestLoading: state.signin.get('RestLoading'),
     fetchRestaurantsError: state.signin.get('fetchRestaurantsError'),
     SnacksLoading: state.signin.get('SnacksLoading'),
     fetchSnacksError: state.signin.get('fetchSnacksError')

   }),
   dispatch => ({
     getData: data => dispatch(Actions.common.getData(data)),
     getUserData: data => dispatch(Actions.main.getUserData(data)),
     addfav: (user, place) => dispatch(Actions.common.addFavourite(user,                                                     
    place)),
      removeFav: (user, index) => dispatch(Actions.common.removeFavourite(user,       
  index)),
            getNearbyrestaurants: (latitude, longitude) =>       
   dispatch(Actions.signin.getNearbyrestaurants(latitude, longitude)),
  getNearbySnacks: (latitude, longitude) => 
 dispatch(Actions.signin.getNearbySnacks(latitude, longitude)),

 })
 )(RestaurantList);