Creating Description Page

In this lesson, we're going to create a description page

Creating description page#

In the last lesson, we created our Category page which was quite straightforward. We had already created ShowCourses component which made things so much simpler to create that page. With the information we have, we can also create a description page. So let's go for it.

If we go to our agent.ts file inside Courses, let's create a new method, getById. It will accept a parameter id which will be a string this time as our Course Id is of type Guid and string is the closest representation to that. We will use get method; response will be of type Course, and the url is courses/id.


Inside pages, we can create a new file called DescriptionPage.tsx, and do the usual import React, create a function DescriptionPage, return a fragment, and export it. We can again create a new state called course; this time, we will give it a type Course and can leave the default value to be empty. We can also use undefined as another type but Typescript is smart enough to know that the initial value is undefined, so it automatically gives it the type. If we put a cursor on course, you will see it has type undefined as well.



Start a new discussion. All notification go to the author.