Professional Documents
Culture Documents
React Components - Building Blocks of UI - by CHAITANYA KURHE - Medium
React Components - Building Blocks of UI - by CHAITANYA KURHE - Medium
React Components - Building Blocks of UI - by CHAITANYA KURHE - Medium
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 1/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
is a syntax extension for JavaScript that allows you to write HTML-like code
within JavaScript.
Functional Components
Functional components are the simplest type of components in React. They
are essentially JavaScript functions that return JSX code to define what
should be rendered on the screen. Functional components are created by
writing a JavaScript function that can receive data as parameters. These
components are recommended for situations where the component does not
require interaction or work with other components. However, multiple
functional components can be composed under a single functional
component.
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 2/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
Class Components
Class components are more complex than functional components and offer
additional features. They are aware of other components in your program
and can work with each other. Class components can pass data from one
component to another and are created using JavaScript ES6 classes. While
functional components are recommended for simpler scenarios, class
components are ideal when components need to interact with each other or
require additional functionality.
increment() {
this.setState((prevState) => ({ count: prevState.count + 1 }));
}
render() {
return (
<div>
Open in app
<h1>Count: {this.state.count}</h1>
<button onClick={() => this.increment()}>Increment</button>
</div>
Search Write
);
}
}
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 3/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
It’s important to note that both functional and class components serve the
same purpose and can achieve similar results. The choice between them
depends on the specific requirements of your application.
Rendering Components
Now that we understand the basics of React components, let’s explore how to
render them on the screen. In a previous article, we learned about rendering
elements in React using the ReactDOM.render() method. React is capable of
rendering user-defined components in addition to DOM elements.
};
method to render the Welcome component to the DOM element with the id of
"root".
Upon executing this code, the Welcome component will be rendered on the
screen, displaying the message "Hello, World!".
Conclusion
React components are the core building blocks of UI in React applications.
They allow developers to break down a UI into smaller, reusable pieces,
making it easier to manage and organize the codebase. React provides two
types of components: functional components and class components.
Functional components are simpler and recommended for scenarios where
components don’t require interaction with other components. Class
components are more complex and offer additional features, making them
ideal for situations that involve interactivity and complex logic. By
understanding the different types of components and how to render them,
you’ll be well-equipped to leverage the power of React in your web
applications.
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 5/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
4 Followers
Computer Engineer | Full Stack Java Developer | React.js Expertise | Technology &
Programming Enthusiast|Frontend Dev-Exploring Different Technologies|Linux
203 7
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 6/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
10 1
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 7/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
What are the best practices for How to Create a Responsive Nav-
styling in React? Bar Component Using React with…
Discover the top styling best practices for Dynamic Nav-Bar Component with React,
React and enhance your web development… typescript, and Bootstrap5 using Vite
4 min read · Nov 24, 2023 4 min read · Sep 30, 2023
Lists
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 8/9
3/25/24, 2:02 PM React Components: Building Blocks of UI | by CHAITANYA KURHE | Medium
139 297 10
7 min read · Sep 29, 2023 9 min read · Feb 26, 2024
52 337 2
https://medium.com/@chaitanya.kurhe18/react-components-building-blocks-of-ui-9c2011a2a1ab 9/9