-
Component InteractReact 2021. 10. 28. 21:49
이 글은 React의 Component Interact중 render함수를 이용한 방식을
간단한 예시를 통해 이해하기 위해 작성하였습니다.< Component Interact >
A React application can contain dozens, or even hundreds, of components.
Each component might be small and relatively unremarkable on its own. When combined, however, they can form enormous, fantastically complex ecosystems of information.
In other words, React apps are made out of components, but what makes React special isn’t components themselves. What makes React special is the ways in which components interact.- A component can render another component.
For Component Interacting!
1. export and import
2. Apply Component in a render function
That's it!ex)
import React from 'react'; import ReactDOM from 'react-dom'; import { NavBar } from './NavBar'; class ProfilePage extends React.Component { render() { return ( <div> <NavBar /> <h1>All About Me!</h1> <p>I like movies and blah blah blah blah blah</p> <img src="https://content.codecademy.com/courses/React/react_photo-monkeyselfie.jpg" /> </div> ); } } ReactDOM.render(<ProfilePage />, document.getElementById('app'));
< ProfilePage.js >
import React from 'react'; export class NavBar extends React.Component { render() { const pages = ['home', 'blog', 'pics', 'bio', 'art', 'shop', 'about', 'contact']; const navLinks = pages.map(page => { return ( <a href={'/' + page}> {page} </a> ) }); return <nav>{navLinks}</nav>; } }
< NavBar.js >
'React' 카테고리의 다른 글
State (0) 2021.10.30 this.props (0) 2021.10.30 React Component (0) 2021.10.27 Advanced JSX (0) 2021.10.27 Intro To JSX (0) 2021.10.26