Reputation: 19
I am trying to check if the user has a username to allow him to upload images otherwise i want to ask the user to login but i try to do that this error appears :
TypeError: Cannot read property 'displayName' of null
App
C:/Users/User/Desktop/try-react/new-app/src/App.js:91
this it the code which causes the error:
return (
<div className="app">
{user.displayName ? <ImageUpload username={user.displayName} /> : <h3>login</h3>}
Upvotes: 1
Views: 79
Reputation: 629
Your user has null value. Use this for null check
{user ? <ImageUpload username={user?.displayName} /> : <h3>login</h3>}
Upvotes: 1