Form and Routes : LC Board
In the first week, we focused on Tailwind CSS. We will skip the mobilve navbar for now, and revisit it later towards the end of the project. If you’re not able to wrap your head around Tailwind CSS, no worries, the second week doesn’t involve a lot of CSS. In the second week, we will focus on the documentation of NextJS, some concepts of React (Hooks and Props), Zod,
Create a page /problems
. This page should contain a form (created using shadcn/ui components) that takes the problem ID as input. Upon submitting the form, it should redirect to a new page /problems/123
. Here 123
is the actual problem ID that the user entered into the form. This page should contain Hello 123
in a card, where 123
is the problem ID.
- Create a form component in the file
components/custom/lc-form.tsx
- Use Zod to define the schema for the form input. Zod handles the user validation for you. Try entering something which is not an integer in the input area and see what happens.
- Read about what is a Single Page Application (SPA). Figure out how to navigate from one page to another without refreshing the entire page. This is where the documentation of
router
fromnext/navigation
andLink
fromnext/link
would come in handy. - If this is really an SPA, and we don’t do a refresh of the entire site, how do we update the title of the webpage? Read about the
useEffect
React hook. - How do we get the url that we are currently on, to detect the problem ID? Read about
useParams
fromnext/navigation
.
Except for the React hooks to update the page title, please do not google about other parts of the exercise. To do them, read the official documentation instead.
- For Forms : Read the shadcn/ui page and google for keywords that you don’t know.
- For routes and navigation : Read the Next JS documentation. On the left hand side, you will a section called Routing. In this section, these are the pages that you need to read:
- Defining routes
- Pages
- Layouts and Templates
- Linking and Navigating
- Redirecting
- Dynamic Routes
They are very beginner friendly, and contains good visualization. Make sure to go through them.