What is components in react.s?:
- Components is a resuable piece of UI like (button,card,navbar,form).
- Component is a building block of a React application.
- Components can be reused anywhere in the app.
- Two types of components functional and class components.
- Each components can handle its own logic,styling,and state.
- Javascript function or class that returns HTML like JSX.
There are Types of Components:
- Functional Components (it is morden version)
- Class Components (older, less used now)
Functional Components example:
Is this function returns JSX
function message(){
retun(
<h1> Hi Lakshmi!..</h1>;
)
}
Class Components example:
Written as a JavaScript class.
class Greeting extends React.Component {
render() {
return <h1>Hello, World!</h1>;
}
}
Why do we use Components?:
- Reuse code (write ones, use multiple times ).
- Readable(code is easier to mange).
- UI can be separated into smaller parts.
- Composability small components combine in to big apps
Top comments (0)