Basic React
Basic React
ReactJS is an open-source JavaScript library for building user interfaces, primarily developed
by Facebook. It focuses on the view layer of an application and is used to create reusable UI
components.
3. What is JSX?
JSX stands for JavaScript XML, a syntax extension for JavaScript that looks similar to HTML.
It’s used in React to describe the UI structure.
The Virtual DOM is a lightweight JavaScript representation of the real DOM. React uses it to
ef ciently update and render components by calculating differences (dif ng) and applying
only the necessary changes to the real DOM.
Components are the building blocks of a React application. They can be functional (stateless)
or class-based (stateful) and are used to de ne the UI structure.
fi
fl
fi
fi
6. What is the difference between functional and class components?
• Functional Components: Simpler, use React Hooks for state and lifecycle, no this
keyword.
• Class Components: Use this, can have lifecycle methods, and are more verbose.
Props (short for properties) are read-only data passed from a parent component to a child
component. They allow dynamic rendering of components.
State is a built-in object in React used to store data that may change over time. It is local to
the component and can be updated using setState or useState.
Keys are used in lists to help React identify and manage individual elements ef ciently during
updates. Keys should be unique for each element.
12. What are React Hooks?
React Hooks, introduced in React 16.8, enable state and lifecycle features in functional
components.
Common hooks include:
• useState: Manage state.
• useEffect: Handle side effects.
• useContext: Access context.
useEffect is a React Hook used for performing side effects such as fetching data, updating
the DOM, or setting subscriptions.
React handles events using synthetic events, which are cross-browser wrappers for native
events. Events are named in camelCase (e.g., onClick).