React.js로 처음으로 작업하면서 꽤 간단한 작업을하고 싶었습니다.react.js에서 재사용 가능한 구성 요소 또는 부분을 만드는 방법은 무엇입니까?
나는 내 탐색 기능이있는 초기 페이지를로드하고 appps.js를 생성하여 하위 탐색 도구를 내뱉습니다.
탐색을 app.js 파일에 넣는 대신, 다른 구성 요소 또는 부분을 렌더링하여 렌더링하고 싶습니다. 아래
코드 :
import React, { Component } from 'react';
import NavLink from './components/NavLinks/NavLinks'
import './App.css';
import { Link } from 'react-router';
class App extends Component {
render() {
return (
<div className="App">
<nav>
<li><NavLink to="/">Home</NavLink></li>
<li><NavLink to="/contact" activeClassName="active">Contact</NavLink></li>
<li><NavLink to="/bad-link" activeClassName="active">Bad Link</NavLink></li>
</nav>
<div className='container'>
{this.props.children}
</div>
</div>
);
}
}
export default App;
내가 좋아하는 것이 무엇 :이 같은
class App extends Component {
render() {
return (
<div className="App">
{-- Some component or partial here to render the nav --}
<div className='container'>
{this.props.children}
</div>
</div>
);
}
}
export default App;