I learn React and now I dont understand this Eslint warning.
Can someone explain please the Eslint docs don't make sense I see other code doing what I do and still no warning.
If I replace the switch
statement in this method getProviders
the Eslint warning go away so it have to do with the switch
??
This is the code:
import React from 'react';
import '../../styles/profile-page-anonymous.css';
import { compose } from 'recompose';
import { withFirebase } from '../../firebase';
import { AuthUserContext, withAuthorization } from '../../session';
import ChangeName from './ChangeName';
import * as ROLES from '../../constants/roles';
class ProfilePageBase extends React.Component {
constructor(props) {
super(props);
this.state = {
displayName: props.authUser.displayName ?? '',
};
this.nameChange = this.nameChange.bind(this);
this.getProviders = this.getProviders.bind(this);
}
getProviders(authUser) {
switch (authUser.providerData[0].providerId) {
case 'google.com': {
return authUser.providerData[0].email;
}
case 'facebook': {
return authUser.providerData[0].providerId;
}
case 'twitter': {
return authUser.providerData[0].providerId;
}
default:
return 'non';
}
}
nameChange(displayName) {
this.setState({
displayName,
});
}
render() {
let userDetails;
const { authUser } = this.props;
const { displayName } = this.state;
const providers = this.getProviders(authUser);
if (authUser) {
userDetails = (
<div>
<div className="profileAnonymous">
<table>
<tbody>
<tr>
<td>Display name: </td>
<td>{displayName}</td>
</tr>
<tr>
<td>User ID: </td>
<td>{authUser.uid}</td>
</tr>
<tr>
<td>Signed in with: </td>
<td>{providers}</td>
</tr>
</tbody>
</table>
</div>
<div>
<h2>Change your display name</h2>
</div>
<div className="profileBoxChangeName">
<ChangeName authUser={authUser} callback={this.nameChange} />
</div>
</div>
);
} else {
userDetails = <p>Unable to get user details. Please try refreshing the page.</p>;
}
return <div>{userDetails}</div>;
}
}
const ProfilePageAuth = props => (
<AuthUserContext.Consumer>
{authUser => (
<div className="profilePageAuthenticated">
<ProfilePageBase {...props} authUser={authUser} />
</div>
)}
</AuthUserContext.Consumer>
);
const condition = authUser => authUser && authUser.roles.includes(ROLES.USER);
const enhance = compose(withAuthorization(condition), withFirebase);
const ProfilePageAuthenticated = enhance(ProfilePageAuth);
export default ProfilePageAuthenticated;