concept datum in category nextjs

This is an excerpt from Manning's book Next.js in Action.
Static websites that predate the modern web were comprised mainly of HTML files and other resources that formed parts of those pages, like images and stylesheets. The browser would request a URL and the server would return content that was ready to display. Today, much of the content that we see on the web is generated dynamically. For example, React applications are made up of components that are implemented via JavaScript. Before any content can be displayed, a bunch of JavaScript needs to run. Often, data needs to be fetched from an API endpoint before any content is visible to the user. While we can do a lot more with modern technology, it comes at a cost. Static content that comes from the server, ready to display, means less wait time for the user and an overall better experience.
Figure 1.4: Data flowing through a React application
![]()
It might take a few tries to put together something that accurately captures the markup. The trick is, only focus on data found in the markup on the page right now. Otherwise, you’ll end up getting sidetracked. The focus right now is keeping the page self-contained and markup that uses data passed in by Next.js. Now we can try implementing getInitialProps on the home page:
Listing 3.21: The getInitialProps function of the home page, returning data that is passed to the page component as properties
Home.getInitialProps = async function() { return { messages: [ { id: 1, sent: "2 minutes ago", content: "Did you see this?", from: { name: "josh", displayName: "Josh" } }, { id: 2, sent: "1 hour ago", content: "I can't tell if it's on or not...", from: { name: "beth", displayName: "Beth" } }, { id: 3, sent: "3 hours ago", content: "You don't need it for another week?", from: { name: "ryan", displayName: "Ryan" } } ], friends: [ { name: "beth", displayName: "Beth" }, { name: "ryan", displayName: "Ryan" } ] }; };
The data that we’ve taken from the static markup and moved into JSON data returned by getInitialProps is an object with two arrays – messages and friends. These two properties will be passed to the Home page component. Let’s look at how we can adjust the page content to make use these two properties: