【问题标题】:Props passed to the enclosed component of withAuthenticator HOC is empty传递给 withAuthenticator HOC 封闭组件的 Props 为空
【发布时间】:2020-11-19 02:19:59
【问题描述】:

我期待props.onStateChange,但 props 是空对象。

传递给withAuthenticator HOC 的封闭组件的道具是空的。

import { withAuthenticator } from "@aws-amplify/ui-react";


export const App = withAuthenticator((props) => {
  console.log('props',props) // {}
  return (
    <BrowserRouter>
      ......
    </BrowserRouter>
  );
});

我想要完成的是sign-out 功能。我试过Auth.signOut()。但这只是清除localStorage,但没有重定向到sign-in页面。

我搜索了这个问题,发现

当在 withAuthenticator 中使用 Auth.signOut 时,它会 不注销,因为它只是在本地更新会话 本地存储。您需要有一种方法来重新渲染实际 withAuthenticator 组件。

https://github.com/aws-amplify/amplify-js/issues/1529

https://github.com/aws-amplify/amplify-js/issues/4643

提供的解决方案包括使用props.onStateChange,但在我的情况下,道具是空的。

我哪里错了?

【问题讨论】:

标签: reactjs amazon-web-services aws-amplify


【解决方案1】:

经过一些研发,我发现

import { withAuthenticator } from "@aws-amplify/ui-react";

这里withAuthenticator HOC 不提供任何道具。

而且这种方式用于使用预构建的 UI 组件

import { withAuthenticator } from "aws-amplify-react";

这里withAuthenticator HOC 提供道具

  • authState
  • authData
  • onStateChange.

这种方法用于定制(创建)我们自己的 UI。

【讨论】:

    猜你喜欢
    • 2020-01-26
    • 2019-09-13
    • 1970-01-01
    • 2019-08-09
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多