ReasonJun

React : Why use React? (Declarative Syntax) 본문

Frontend/React

React : Why use React? (Declarative Syntax)

ReasonJun 2023. 6. 11. 00:04
728x90

Declarative syntax is a fundamental concept in React that defines how UI components are structured and rendered. In React, you describe the desired state of your user interface, and React takes care of updating the actual DOM to match that state. This declarative approach contrasts with an imperative approach, where you manually manipulate the DOM to reflect changes in the UI.

In React's declarative syntax:

  1. Component-Based Structure: React breaks down the user interface into reusable and self-contained components. Each component represents a specific part of the UI and encapsulates its logic, state, and rendering. Components can be composed together to create more complex UI structures.
  2. Component Hierarchy: React components are organized in a hierarchical structure, forming a tree-like architecture. This hierarchy helps in defining the relationship between components and their composition. Each component can have child components, and changes in parent components can propagate to their children.
  3. Component Rendering: React provides a mechanism to define how components should be rendered based on their current state and props. Components are written using JSX (JavaScript XML), which is a syntax extension that allows you to write HTML-like code within JavaScript. JSX provides a concise and familiar syntax for describing the structure of the UI.
  4. State and Data Binding: React components can have a state that represents the data and stateful behavior of the component. The state is managed internally by React and can be updated by the component itself. React automatically re-renders the components when their state changes, ensuring that the UI reflects the updated state.
  5. Virtual DOM Diffing: As mentioned earlier, React uses a Virtual DOM to efficiently update the actual DOM. When the state of a component changes, React performs a diffing process to identify the minimal changes required to update the UI. You don't need to manually manipulate the DOM; React handles the updates for you.
728x90
Comments