import { Component } from "react";
class App extends Component{
render(){
const name = 'react';
return <div className="react">{name}</div>
}
}
export default App;
1. **Import React Component**: The snippet begins by importing `Component` from the React library. This is necessary to extend the `Component` class when creating a class component in React.
2. **Class Component Definition**: The `App` class is defined, extending the `Component` base class from React. This allows `App` to inherit methods and properties from `Component`, enabling it to behave as a React component.
3. **The `render` Method**:
- Within the `App` class, the `render` method is defined. The `render` method is a required lifecycle method in class components. It specifies what the UI looks like for the component.
- Inside the `render` method, a constant named `name` is declared and assigned the string `'react'`. This constant is then used within the returned JSX to dynamically insert the value of `name` into the rendered output.
4. **Returning JSX**: The `render` method returns JSX, a syntax extension for JavaScript that looks similar to HTML. The returned JSX contains a `div` element with a class name of `"react"` and displays the value of the `name` constant inside the `div`. This results in the text 'react' being rendered within a `div` on the webpage.
5. **Exporting the Component**: Finally, the `App` component is exported as the default export of the file, making it available for import in other parts of the application. This is a common pattern in React applications, allowing components to be modular and reusable.
'개념 > React' 카테고리의 다른 글
React) Creating a Responsive Color Box Layout with Sass in React (0) | 2025.04.15 |
---|---|
SCSS) ..... utils.scss (0) | 2025.04.14 |
React) class_component_state (0) | 2025.04.12 |
React) class_component_props (0) | 2025.04.11 |
React) isRequired (0) | 2025.04.10 |