【问题标题】:Apollo resetStore doesn't work阿波罗 resetStore 不起作用
【发布时间】:2018-04-26 10:37:42
【问题描述】:

请帮忙; 我有一个错误“未定义不是一个对象(评估'this.props.client')

class FeedProfileBottom extends Component {

_onLogoutPress = function() {
  this.props.client.resetStore();
  return this.props.logout();
}

render() {
  return (
    <Root>
      <LogOutButton onPress={this._onLogoutPress}>
        <LogOutText>
          Logout
        </LogOutText>
      </LogOutButton>
    </Root>
  );
 }
}

export default withApollo(connect(undefined, { logout })(FeedProfileBottom));

【问题讨论】:

  • 您是否尝试过将组件范围显式绑定到您的注销功能?
  • @NickZuber 谢谢,成功了。
  • 我添加了这个作为对您问题的回答——如果您是这样解决的,您介意将其标记为正确,以便其他有类似问题的人发现解决方案吗?

标签: react-native react-apollo apollo-client


【解决方案1】:

您可能需要将组件的范围显式绑定到您的函数。

class FeedProfileBottom extends Component {
  constructor (props) {
    super(props);
    this._onLogoutPress = this._onLogoutPress.bind(this);
  }
  // ...

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 2020-09-26
    • 2020-05-09
    • 2019-02-15
    • 2013-02-02
    • 2021-12-28
    • 2017-10-15
    • 2021-09-09
    • 2017-08-01
    相关资源
    最近更新 更多