Putting the app together

After implementing all components, in order to reproduce the mock-up, we now only have to put everything together in the App component. Then, we will have successfully reproduced the mock-up!

Let's start modifying the App component, and putting our app together:

  1. Edit src/App.js, and remove all of the current code.
  2. First, we import React, PostList, CreatePost, and the UserBar components:
import React from 'react'

import PostList from './post/PostList'
import CreatePost from './post/CreatePost'
import UserBar from './user/UserBar'
  1. Then, we define some mock data for our app:
const user = 'Daniel Bugl'
const posts = [
{ title: 'React Hooks', content: 'The greatest thing since sliced bread!', author: 'Daniel Bugl' },
{ title: 'Using React Fragments', content: 'Keeping the DOM tree clean!', author: 'Daniel Bugl' }
]
  1. Next, we define the App component, and return a <div> container element, where we set some padding:
export default function App () {
return (
<div style={{ padding: 8 }}>
  1. Now, we insert the UserBar and CreatePost components, passing the user prop to the CreatePost component:
            <UserBar />
<br />
<CreatePost user={user} />
<br />
<hr />
Please note that you should always prefer spacing via CSS, rather than using the <br /> HTML tag. However, at the moment, we are focusing on the UI, rather than its style, so we simply use HTML whenever possible.
  1. Finally, we display the PostList component, listing all posts:
            <PostList posts={posts} />
</div>
)
}
  1. After saving the file, http://localhost:3000 should automatically refresh, and we can now see the full UI:

Full implementation of our static blog app, according to the mock-up

As we can see, all of the static components that we defined earlier are rendered together in one App component. Our app now looks just like the mock-up. Next, we can move on to making all of the components dynamic.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.77.114