React: 선언형, 컴포넌트 기반, 범용가능
JSX: Javascript를 확장한 문법. JSX를 이용해서 React element를 만든다. 브라우저가 실행하기 위해서는 Babel을 이용한다.
하나의 js파일에서 html&js가 했던 일을 한번에 처리
element class 사용시 className으로 표기
js식 표현 사용시 중괄호 {} 이용
let name = 'Yonnie';
return(
<div>
My name is {name}
</div>
);
<div>
{
(1+1===2)?(<p>true</p>):(<p>false</p>)
}
</div>
const content = 딕셔너리.map((post) =>
<div key={post.id}>
<h3> {post.title}>
...
import './App.css';
function App() {
const words = [
"안녕 안녕 나는 요니야",
"이건 리액트야",
"옆엔 해리가 자고있지"
]
const getRandomIndex=(length)=>{
return parseInt(Math.random() * length);
}
return (
<div className = "App" >
<header className = "App-header" >
{words[getRandomIndex(words.length)]}
</header>
</div>
);
}
export default App;
App 컴포넌트의 후손 컴포넌트로 sidebar 컴포넌트가 있어야 함.
Font Awesome을 활용하여 트윗메세지 아이콘이 있어야함.
Counter 컴포넌트가 있어야함 (total수)
Footer컴포넌트가 있어야함
트윗 저자의 프로필사진, 유저이름, 생성일자, 메시지 등 구현
조건부 렌더링을 활용, username 배경색이 특정 색이 되도록 클래스 지정
import React from 'react';
import './App.css';
import { dummyTweets } from './static/dummyData';
// ! 위 코드는 수정하지 않습니다.
console.log(dummyTweets) // 개발 단계에서 사용하는 더미 데이터입니다.
const Sidebar = () => {
return (
<section className="sidebar">
<i className="far fa-comment-dots"></i>
<i className='far fa-bell'></i>
</section>
);
};
const Counter = () => {
return (
<div className="tweetForm__input">
<div className="tweetForm__inputWrapper">
<div className="tweetForm__count" role="status">
total: {dummyTweets.length}
</div>
</div>
</div>
);
};
const Footer = () => {
return <div>
<footer>Copyright @ 2021 Code States</footer>
</div>;
};
// TODO : Footer 함수 컴포넌트를 작성합니다. 시멘틱 엘리먼트 footer가 포함되어야 합니다.
const Tweets = () => {
return (
<ul className="tweets">
{dummyTweets.map((tweet) => {
const isParkHacker = tweet.username === 'parkhacker'
const tweetUserNameClass = isParkHacker
? 'tweet__username tweet__username--purple'
: 'tweet__username';
return (
<li className="tweet" key={tweet.id}>
<div className="tweet__profile">
<img src={tweet.picture}></img>
</div>
<div className="tweet__content">
<div className="tweet__userInfo">
<span className={tweetUserNameClass}> {tweet.username}</span>
<span className="tweet__createdAt">{tweet.createdAt}</span>
</div>
<div className="tweet__message">{tweet.content}</div>
</div>
</li>
);
})}
</ul>
);
};
const Features = () => {
return (
<section className="features">
<div className="tweetForm__container">
<div className="tweetForm__wrapper">
<div className="tweetForm__profile"></div>
<Counter />
</div>
</div>
<Tweets />
<Footer/>
</section>
);
};
const App = () => {
return (
<div className="App">
<main>
<Sidebar/>
<Features />
</main>
</div>
);
};
// ! 아래 코드는 수정하지 않습니다.
export { App, Sidebar, Counter, Tweets, Features, Footer };