pairof9s pairof9s - 1 year ago 72
React JSX Question

Display logged in user's first name onto page (from database)

In preparing a welcome page after a user has logged in, I'd like the page title to display their first name which is found in the user ID database (e.g - "Welcome, Sally!"). This is a bit different than just using a cookie to relay the username in a location; like for example in the top corner to access user settings.

The site is being built with React, if that affects the code needed.

Any suggestions?

Answer Source

are you asking how to get the username in the app state? or just how you would render that?

if you already have the firstname in an auth object in state you could do something like this:

class WelcomePage extends Component {
   render() {

      const { auth } = this.props

      var pageTitle = `Welcome, { auth.firstname }`

      return (
         <h1>{ pageTitle }</h1>

export default WelcomePage

otherwise I would need more information to understand what you're asking

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download