Skip to content

Commit f8f4b33

Browse files
committed
fix: fix error when userName is empty or undefined
(cherry picked from commit 32ea6b0bad29c85d89834c198688a53cb7acc033)
1 parent 2158502 commit f8f4b33

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/misc/DefaultAvatar/DefaultAvatar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const useStyles = makeStyles((theme) => ({
2929
},
3030
}));
3131

32-
export const DefaultAvatar = ({ userName, size = 24, variant = 'circular' }) => {
32+
export const DefaultAvatar = ({ userName = '?', size = 24, variant = 'circular' }) => {
3333
const avatarBackgroundColor = stringToColor(userName);
34-
const letter = String.fromCodePoint(userName.codePointAt(0)).toUpperCase();
34+
const letter = userName === '' ? '?' : String.fromCodePoint(userName.codePointAt(0)).toUpperCase();
3535

3636
const classes = useStyles({ avatarBackgroundColor, size });
3737

@@ -46,7 +46,7 @@ DefaultAvatar.propTypes = {
4646
/**
4747
* User name to get first letter and compute avatar's color
4848
*/
49-
userName: PropTypes.string.isRequired,
49+
userName: PropTypes.string,
5050
/**
5151
* Icon size in pixels
5252
*/

0 commit comments

Comments
 (0)