title: How can I connect a post to its username?
body: <p>I'm using react for the client side and rails for the server.
  When trying to link the post to its username I get 'undefined'.</p>
  <p>If I try <code>user={post.user_id}</code> to get the user_id, it works fine, but I want to show the username.</p>
  <p><strong>PostList.jsx</strong></p>
  <pre><code>{posts.map((post) =&gt; (
    &lt;&gt;
    &lt;Post
      key={post.id}
      title={post.title}
      content={post.content}
      user={post.user.username}
      id={post.id}
      getPosts={getPosts} /&gt;
    &lt;/&gt;
  </code></pre>
  <p><strong>Post.jsx</strong></p>
  <pre><code>const Post = ({title, content, user, id, getPosts}) =&gt; {
  
    return (
      &lt;div className='post-container'&gt;
        &lt;div className='post-header'&gt;
          &lt;div className='post-title-user'&gt;
            &lt;h2&gt;{title}&lt;/h2&gt;
            &lt;span&gt;Posted by: #{user}&lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;p&gt;{content}&lt;/p&gt;
      &lt;/div&gt;
    )
  }
  
  export default Post
  </code></pre>
  <p><strong>schema.rb</strong></p>
  <pre><code>  create_table &quot;posts&quot;, force: :cascade do |t|
      t.string &quot;title&quot;
      t.text &quot;content&quot;
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
      t.integer &quot;user_id&quot;, null: false
      t.index [&quot;user_id&quot;], name: &quot;index_posts_on_user_id&quot;
    end
  
    create_table &quot;users&quot;, force: :cascade do |t|
      t.string &quot;username&quot;
      t.string &quot;password_digest&quot;
      t.datetime &quot;created_at&quot;, precision: 6, null: false
      t.datetime &quot;updated_at&quot;, precision: 6, null: false
    end
  </code></pre>
  <p><strong>user.rb</strong></p>
  <pre><code>class User &lt; ApplicationRecord
    has_secure_password
    has_many :posts
  end
  </code></pre>
  <p><strong>post.rb</strong></p>
  <pre><code>class Post &lt; ApplicationRecord
    belongs_to :user
  end
  </code></pre>