小编nab*_*eel的帖子

如何异步/等待redux-thunk动作?

action.js

export function getLoginStatus() {
  return async(dispatch) => {
    let token = await getOAuthToken();
    let success = await verifyToken(token);
    if (success == true) {
      dispatch(loginStatus(success));
    } else {
      console.log("Success: False");
      console.log("Token mismatch");
    }
    return success;
  }
}
Run Code Online (Sandbox Code Playgroud)

component.js

  componentDidMount() {
    this.props.dispatch(splashAction.getLoginStatus())
      .then((success) => {
        if (success == true) {
          Actions.counter()
        } else {
          console.log("Login not successfull");
        }
     });
   }
Run Code Online (Sandbox Code Playgroud)

但是,当我用async/await编写component.js代码时,我得到此错误:

Possible Unhandled Promise Rejection (id: 0): undefined is not a function (evaluating 'this.props.dispatch(splashAction.getLoginStatus())')

component.js

  async componentDidMount() {
     let success = …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native redux-thunk react-redux ecmascript-2017

30
推荐指数
4
解决办法
3万
查看次数

Django - 如何运行函数EVERYDAY?

我想每天午夜运行这个功能来检查expiry_date_notification.我能做什么?我是django和python的新手.

def check_expiry_date(request):
    products = Product.objects.all()
    for product in products:
        product_id = product.id
        expiry_date = product.expiry_date
        notification_days = product.notification_days
        check_date = int((expiry_date - datetime.datetime.today()).days)
        if notification_days <= check_date:
            notification = Notification(product_id=product_id)
            notification.save()
Run Code Online (Sandbox Code Playgroud)

django recurrence notifications date django-timezone

7
推荐指数
1
解决办法
5961
查看次数

DRF:如何将django-rest-framework-jwt与Djoser集成

我打算用Django Rest Framework构建一个应用程序.我对使用Django-Rest-Framework-JWT认证机制比使用SessionToken认证机制更感兴趣.

但是所有其他软件包,如Django-Rest-AuthDjoser(有助于注册过程)都使用Session和Token Authentication系统.

如何使用Django-Rest-Framework-JWT覆盖DjoserDjango-Rest-Auth中的令牌认证机制?

authentication django jwt django-rest-framework django-rest-auth

7
推荐指数
1
解决办法
3187
查看次数

在 RN ScrollView 中动态设置 scrollEnabled 为 False

scrollEnabled当滚动到达某个位置时,如何更改React Native ScrollView param的 bool 值?

我确实在 ScrollView 中有一个 ScrollView,由于外部 ScrollView,内部 ScrollView 没有响应。当scrollEnabled参数设置为False外部 ScrollView时,内部 ScrollView 起作用。我的想法是将外部 ScrollView 动态设置为scrollEnabled={false}到达底部时。我该怎么做呢。

谢谢,

react-native react-native-listview react-native-scrollview react-native-android

2
推荐指数
1
解决办法
5290
查看次数