我收到以下錯誤,雖然我回一個根元素:Route.render():有效的做出反應元素(或空)必須返回
Route.render():有效的做出反應元素(或null)必須返回。您可能返回了未定義的數組或其他一些無效的對象。
調度是不是一個函數
我的代碼:
export var PrivateRoute = ({ component: Component, ...rest }) => {
return (
<Route {...rest} render={props => {
firebase.auth().onAuthStateChanged((user) => {
if(user) {
console.log('ON...ON');
var {dispatch} = props;
dispatch(actions.login(user.uid));
dispatch(actions.startAddTodos());
return(
<Component {...props} />
) ;
} else {
console.log('OFF...OFF');
dispatch(actions.logout());
return (
<Redirect to={{ pathname: '/login', state: { from: props.location } }} />
);
}
});
}} />);
}
export default Redux.connect()(PrivateRoute);
你的回報是異步回調中,而不是直接返回功能正在'道具'作爲論點 –
@MohammadElbanna:謝謝,你能否提出解決問題的方法,請 –
我發佈了一個解決這個問題的建議。希望它有效! –