ReactJS_Guide (1)
ReactJS_Guide (1)
1. What is React?
React is an open-source JavaScript library for building user interfaces, primarily through reusable
components. Its maintained by Facebook and is widely used for creating dynamic, single-page
applications.
Example:
import React from 'react';
import ReactDOM from 'react-dom';
2. Components in React
Components are the building blocks of a React application. They can be functional (stateless) or
class-based (stateful, though less common now with hooks).
Functional Components: Modern, simpler, use hooks for state and side effects.
Class Components: Older approach, use lifecycle methods.
Example:
import React from 'react';
Example:
import React, { useState } from 'react';
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
<button onClick={() => setCount(count - 1)}>Decrement</button>
</div>
);
};
5. Event Listeners
React handles events (like clicks) with synthetic events, and you can add/remove logic using hooks
like useEffect.
Example:
import React, { useState } from 'react';