imp-js
imp-js
Unit -3
1.Define Hooks? What are the rues for using hooks? Create a counting
application that uses a ‘count’ state and updates the value of count on
the title bar. Show the use of useState and useEffect hooks in the
above problem.
Solution
What are Hooks?
Hooks are a new addition to React that allow you to use state and other React
features from functional components. Before hooks, you could only use state and
other React features from class components. Hooks are more concise and easier
to use than class components, and they make it possible to write more reusable
and maintainable React code.
Always call hooks at the top level of your component: Hooks should be
called directly at the top level of your component, before you return
anything. This ensures that they are always called in a consistent order.
Don't modify state directly: Instead of directly mutating state, you should
always use the state updater functions provided by hooks. This ensures that
React can track changes to your state and trigger updates accordingly.
React Router is a popular routing library for React applications. It allows you to
define routes for different parts of your application and render the
corresponding components when a user navigates to those routes. This makes it
easy to create complex single-page applications (SPAs) with multiple pages.
Hash router: This type of router uses the hash fragment of the URL to store the
current route. This means that the URL will not change when the user navigates
between different routes, which can be useful for applications that do not need
to be SEO-friendly.
History router: This type of router uses the HTML5 history API to store the
current route. This means that the URL will change when the user navigates
between different routes, which is more SEO-friendly.
3. Create a simple web page with navigation links for Home page,
Login Page and Sign up page using Reactstrap Navbar component.
Implement the same using React Route concepts.
4. What is the purpose of Redux in a react application? In what
scenarios it is beneficial to use Redux for state management?
Redux is a JavaScript state container that helps manage and organize state in
React applications. It provides a centralized store for holding the application's
state and a unidirectional data flow mechanism for updating state. This makes
it particularly useful for large and complex applications where managing state
becomes challenging.
Unit-4
5. Create a static API using JSON servercontaining a data of Restasurant with
Dish ID, Image of Dish, Components of Dish, Description. Perform all the CRUD
operations.
6.What are the steps to connect JSON data to a react application? Explain in
detail with example.
Example