首先是一些上下文。在Redux容器中使用更高階的組件
我正在使用Redux來管理我的應用程序的身份驗證狀態,並將Auth
作爲Redux容器(或智能組件)。
我創建了一個包裝(高階組件),其採用Auth
並返回:
export default function AuthWrapper(WrappedComponent) {
class Auth extends Component {
... <Auth stuff here> ...
}
return connect(mapStateToProps, mapDispatchToProps)(Auth);
}
在我看來,爲了使用包裝,我只需要調用它我想要在我的身份驗證後面添加一個組件。例如,假設我驗證了一個名爲UserPage
與包裝物成分,點菜:
const AuthenticatedUserPage = AuthWappper(UserPage)
然而,當我使用包裝這樣的,陣營不樂意和我在一起。我得到以下錯誤:
Warning: AuthenticatedApp(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.
我最好的猜測是,它並不像connect
-ified組件,當我從AuthWrapper
返回它是終極版將創造......這使我對我的問題:
當這些組件創建Redux容器時,React是否支持更高階的組件?如果是這樣,爲什麼React會拋出這個錯誤?
也很重要:http://stackoverflow.com/questions/42307736/redux-higher-order-components-same-as-container-components?rq=1 –