본문 바로가기
개념/React

React) mycomponent

by kiseno 2025. 4. 8.
728x90
반응형
SMALL

mycomponent

const MyComponent = () =>{
    return <div>my new component</div>;
};

export default MyComponent;

main

import Mycomponent from "./mycomponent";

const App=() =>{
    return <Mycomponent/>;
};

export default App;

### Functional Component Structure

- **Function Definition**: `MyComponent` is defined as an arrow function, a common syntax for creating functional components in React. Functional components are a simpler way to write components that only contain a `render` method and don't hold state (before the introduction of Hooks in React 16.8).

- **JSX Return**: The function returns JSX, a syntax extension for JavaScript that looks like HTML. In this case, `MyComponent` returns a `div` element with the text "my new component". JSX is a concise and readable way to specify the UI structure within JavaScript.

### Exporting the Component

- **Export Statement**: The component is exported using the `export default MyComponent;` statement at the end of the file. This makes `MyComponent` available for import in other parts of the application. The default export means you can import it with any name you choose in the importing file.

### Usage

To use `MyComponent` in another part of your React application, you would import it using an import statement at the top of a JavaScript (JSX) file, like so:

```jsx
import MyComponent from './MyComponent'; // Adjust the path as necessary
```

And then you can use it within the JSX of another component just like any other component:

```jsx

const App = () => {
    return (
        <div>
            <MyComponent />
        </div>
    );
};


```

728x90
반응형
LIST

'개념 > React' 카테고리의 다른 글

React) isRequired  (0) 2025.04.10
React) multiple state value  (0) 2025.04.09
React) mycomponent props children  (0) 2025.04.07
React) myComponent props value  (0) 2025.04.06
React) out of value to props  (0) 2025.04.05