While updating react from ver 15 to ver 16 I got this error:
Cannot read property 'forEach' of undefined in PrivateRoute component.
Package JSON shows those versions:
"react": "^16.10.1",
"react-dom": "^16.10.1",
"react-router": "^5.1.1",
"react-router-dom": "^5.1.1",
"react-router-redux": "*"
Here is component code to look at:
I tried to install eslint and eslint-loader as I found that this might be the problem but no luck
import React from "react";
import { Route, Redirect } from "react-router-dom";
const PrivateRoute = ({
component: Component,
Authenticated,
AdminPage,
Admin,
...props
}) => (
<Route
{...props}
render={props => {
if (AdminPage) {
if (Authenticated && Admin) {
return <Component {...props} />;
} else {
return (
<Redirect
to={{
pathname: "/",
state: { from: props.location }
}}
/>
);
}
} else {
if (Authenticated) {
return <Component {...props} />;
} else {
return (
<Redirect
to={{
pathname: "/login",
state: { from: props.location }
}}
/>
);
}
}
}}
/>
);
export default PrivateRoute;