Course Content
Expert React
4. Formik
Powerful Form Library for ReactGet Started with FormikCustom Formik HookInvolve Formik into React componentAdd Initial ValuesForm SubmissionForm ValidationChallenge OverviewChallenge: useFormik HookChallenge: Binding Formik with React ComponentChallenge: Add Initial ValuesChallenge: Form SubmissionChallenge: ValidationFormik Section Sum Up
6. Next Steps
Expert React
Challenge: Route Basic Concepts
Note
All challenges may appear broken by default since they contain whitespace sections where you need to input the necessary code. Once you correctly fill in these whitespace sections, the completed code will be displayed on the live page.
Task 1
Your task is to enhance the app by implementing routing and navigation functionality. The app has two main views: the home page (HomePage
component) and the products page (ProductsPage
component).
To complete this task, follow these steps:
- Wrap the root component (
App
) with theBrowserRouter
component to enable routing functionality. - Import the
HomePage
andProductsPage
components using thelazy
function from React, ensuring they are imported dynamically. - Inside the
App
component, use theSuspense
component to display a loading fallback while the views are being loaded. Utilize theLoader
component for this purpose. - Define the routes using the
Route
component within theRoutes
component, mapping each route path to the corresponding component.- Set the
/
path to lead to the HomePage` component. - Set the
/products
path to lead to theProductsPage
component.
- Set the
- In the
NavBar
component, create links to the corresponding routes using theLink
orNavLink
components.
Ensure that your implementation allows users to navigate between the home and products pages seamlessly. Test the app thoroughly to verify the navigation and functionality.
Hint
1. In the
2. To implement lazy-loading, import the
3. Import the
4. Use the
5. When setting a path, use the
6. To create navigation between pages, utilize the
index.js
file, import the
BrowserRouter
component from the React Router library and use
it to wrap the root component, enabling routing functionality.2. To implement lazy-loading, import the
lazy
function from the
React library. 3. Import the
Suspense
component from the React library to add
a fallback to the app. Set the fallback
prop to a value that
will be shown while any view is loading.4. Use the
Route
and Routes
components from the
React Router library to specify routes for the app. 5. When setting a path, use the
path
prop in the
Route
component. Make sure all Route
components
are wrapped with the Routes
component. 6. To create navigation between pages, utilize the
Link
or
NavLink
components from the React Router library. Set the
to
prop with the corresponding path values.
Everything was clear?
Section 2. Chapter 7