Shoutem - Modifying extensions

不想你离开。 提交于 2019-12-13 08:39:10

问题


He, I tried to modify the shoutem.places extension. My custom screen looks like this:

import { screens } from 'shoutem.places';

export default class FixedMediumPlaceDetails extends 
screens.MediumPlaceDetails {    
  render() {    
    const { place } = this.props;
    const { location = {} } = place;
    return (
      <Screen>
        <NavigationBar />
        <ScrollView>
          {this.renderLeadImage(place)}
        </ScrollView>
      </Screen>
    );
  }
}

I am just overriding the render() method, and inside this method I would like to call the renderLeadImage() method from the superclass.

With this implementation I get: this.renderLeadImage() is not a function. So how do I correctly inherit the class and call a superclass' method? Anyhow, is inheritance the preferred way here? Facebook recommends composition over inheritance.


回答1:


screens.MediumPlaceDetails isn't a React Component class, but rather a redux and shoutem.theme decorated class, this is why when you're extending you don't have access to any of renderLeadImage()'s methods.

So you'll have to change your import:

import { MediumPlaceDetails } from 'shoutem.places/screens/MediumPlaceDetails';

EDIT: Fixed copy-paste error.



来源:https://stackoverflow.com/questions/45001157/shoutem-modifying-extensions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!