我有下面的HOC组件,该组件工作正常,但在调度上给我一个错误。我不能在类组件中使用它,但如何解决呢?
const withAuthentication = <Props extends object>(
Component: React.ComponentType<Props>
) => {
class WithAuthentication extends React.Component<Props & FirebaseInterface> {
render(): React.ReactNode {
const { firebase,...props } = this.props
const dispatch = useDispatch()
const [authenticated,setauthenticated] = useState(false)
const { userId,loggedIn } = useSelector(
(state: Record<string,ReduxProvider>) => state.user
)
useEffect(() => {
const listener = firebase.auth.onAuthStateChanged(authUser => {
if (authUser) {
console.log(authUser)
if (!loggedIn) {
firebase.user(userId).once('value',snapshot => {
dispatch(
)
})
}
setauthenticated(true)
} else {
dispatch(
addUser({
})
)
setauthenticated(false)
}
})
return (): void => {
listener()
}
},[setauthenticated,firebase,dispatch,loggedIn,userId])
}
}
return withFirebase(WithAuthentication)
}
export default withAuthentication
任何帮助将不胜感激!