Explain the concept of Hooks in React. Write a code making use of React Hooks that displays four buttons namely, “Red”, “Blue”, “Green”, “Yellow”. On clicking any of these buttons, the code displays the message that you have selected that particular color.
React Hooks are functions that allow functional components to have state, lifecycle methods, and other React features. They were introduced in React 16.8 to provide a way to use state and other React features in functional components instead of class components.
Rules for Using Hooks:
Only use Hooks at the top level of a functional component or a custom hook.
Only call Hooks from functional components or custom hooks; do not call them in regular JavaScript functions.
Hooks should be called in the same order every time the component renders.
Hooks cannot be called conditionally; they should be called in the same order every render.