
๐ก๋ ธ๋ง๋์ฝ๋ ๋๊ผฌ์ค์ ๊ฐ์๋ฅผ ๋ณด๋ฉฐ ๊ณต๋ถํ๋ ์๋ฆฌ์ฆ์ ๋๋ค.
React๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ Node๊ฐ ํ์ํ๋ค.
Node๊ฐ ์ค์น๋์ด์์ง ์๋ค๋ฉด node.js์์ ์ค์นํ์.
Node์ ์ค์น์ฌ๋ถ๋ฅผ ํ์ธํ๊ณ ์ถ๋ค๋ฉด ํฐ๋ฏธ๋์ด๋ CMD์์ ์๋ ์ฝ๋๋ฅผ ์์ฑํ๋ฉด ๋๋ค.
//๋
ธ๋ ๋ฒ์ ํ์ธ, ๋
ธ๋๊ฐ ์์ค์น๋์๋์ง ํ์ธ
node -v
//์ ์์ค์น ๋์์ ๊ฒฝ์ฐ ๋ฒ์ ๋ช
์ด ์ถ๋ ฅ๋๋ค. ์๋๋ผ๋ฉด ์ฌ์ค์น ํ์.
npm -v
์ ์์ค์น๊ฐ ๋์์ ๋ ์๋ ์ด๋ฏธ์ง์ฒ๋ผ ์ถ๋ ฅ๋๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค.

//์ถ๊ฐ ํ์ธ ํญ๋ชฉ
npx
npx๊น์ง ์๋์ด ๋์ด์ผ react๋ฅผ ์ฌ์ฉํ ์ค๋น๊ฐ ์๋ฃ ๋ ๊ฒ์ด๋ค.
๋ง์ฝ npx๊ฐ ์๋๋์ง ์๋๋ค๋ฉด ์๋ ์ฝ๋๋ก ์ค์น ํ ์ ์๋ค.
npm install -g npx
NPM๊ณผ NPX
npm(Node Package Manager)์ node.js์ ๋ชจ๋ ํจํค์ง์ ๋ชจ๋์ ๊ด๋ฆฌํ๋ ๋ ธ๋ ํจํค์ง ๊ด๋ฆฌ์๋ฅผ ๋ป ํ๋ค. ํ์ง๋ง ์์กด์ฑ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(Dependency) ๋ค์ด ์ ์ญ์ด๋ ๋ก์ปฌ์ ์ค์น๋ ์ฑ ๊ด๋ฆฌ๊ฐ ๋๋ฉด ํจํค์ง๊ฐ ์ ๋ฐ์ดํธ ๋์์ ๋, ์ ์ญ์ผ๋ก ๊ด๋ฆฌ๋๊ณ ์๋ ํจํค์ง์ ๋ก์ปฌ๋ก ๊ด๋ฆฌ๋๊ณ ์๋ ํจํค์ง๋ฅผ ๊ฐ๊ฐ ์ ๋ฐ์ดํธ๋ฅผ ํด์ค์ผํ๋ค๋ ๋จ์ ์ด ์๋ค. ์ด๋ฅผ ๋ณด์ํด์ ๋์จ ๊ฒ์ด npx(Node Package eXecut)์ด๋ค.
์๋ ์ฝ๋๋ฅผ ์์๋๋ก ์์ฑ.
my-app์ ์ํ๋ ํ๋ก์ ํธ์ ์ด๋ฆ์ผ๋ก ์์ฑํ๋ฉด ๋๋ค.
์ฐธ๊ณ ๋ก react, react-dom, react-scripts๋ผ๋ ์ด๋ฆ์ผ๋ก๋ ํ๋ก์ ํธ๋ช
์ ์ง์ ํ ์ ์๋ค.
npx create-react-app my-app
cd my-app
npm start
ํ์ง๋ง ์ฌํ๊ฒ๋ ์ต์ ๋ฆด๋ฆฌ์ฆ์์ ๋์ด์ Create React App์ ์ ์ญ ์ค์น๋ฅผ ์ง์ํ์ง ์๋๋ค๊ณ ํ๋ ํฐ๋ฏธ๋์์ ์ ๊ณตํ ํํธ๋๋ก npm์ ์ฌ์ฉํ์ฌ ์ค์น๋ฅผ ํ๋๋ก ํ๋ค.
npm init react-app my-app
๋ณธ์ธ์ด ์์ฑํ ํ๋ก์ ํธ ํด๋์์ package.jsonํ์ผ์ ์ด์ด๋ณด๋ฉด ํฐ๋ฏธ๋์์ ํ๋ ๊ธ์จ๋ก ์๋ดํด์ค script๋ฅผ ๋ณผ ์ ์๋ค.

์ผ๋จ์ ํ๋ก์ ํธ๋ฅผ ์คํ.
npm run start

๐๐ปcreate-react-app github

๐src
์์ผ๋ก ์์ฑํ ๋ชจ๋ ํ์ผ์ ๋ฃ์ ํด๋.
src > index.js
์ต์ํ ๋ชจ์ต์ด ๋ณด์ธ๋ค.
root๊ฐ ์๊ณ , root์์ App์ renderํ๋ ๊ตฌ์กฐ์ด๋ค.
์ root๋ public์ index.html์์ ๋ณผ ์ ์๋ค.
๋ค์ index.js ์ดํด๋ณด๊ธฐ
ํจ์ ์ปดํฌ๋ํธ์ธ App์ด index.js์์ ๋ถ๋ ค์ง๋ ๊ฒ๊น์ง ์ต์ํ ๊ตฌ์กฐ์ด๋ค.


์ฝํ
์ธ ๋ถํฐ css๊น์ง ๋ชจ๋ ์๋ก ์์ ํ ์ ์๋๋ก ์น๋ค ์ง์ ๋ค.
์ด์ ์์์ด๋ค!
srcํด๋ ์์ Button.js๋ผ๋ ํ์ผ์ ํ๋ ๋ง๋ค๊ณ ์๋์ ์ฝ๋๋ฅผ ์ ๋ ฅํ๋ค.
function Button({ text }) {
return <button>{text}</button>;
}
export default Button;
Button์ ๋ณด์ฌ์ค์ผํ๋ ํ์ผ์ Button์ importํด๋ณด์.
import Button from './Button';
function App() {
return (
<div>
<h1>welcome back, React!</h1>
<Button text={'Continue'} />
</div>
);
}
export default App;
์ฐ๋ฆฌ๋ import๋ component Button์ text๊ฐ props๋ณด ์ ๋ฌ๋๋ state๋ผ๋ ๊ฒ์ ์ ์๊ณ ์๋ค.
props์ type์ ๋ณด๋ค ํธ๋ฆฌํ๊ฒ ์ฒดํฌํ๊ธฐ ์ํด propTypes ์ค์น.
npm i prop-types
import PropTypes from 'prop-types';
import Button from './Button';
function App() {
return (
<div>
<h1>welcome back, React!</h1>
<Button text={'Continue'} />
</div>
);
}
Button.prototype = {
text: PropTypes.string.isRequired,
};
export default App;
text์ ํ์ ์ string์ด๊ณ ํ์๊ฐ์ด๋ผ๋ ๊ฒ์ ํ๋์ ํ์ ํ ์ ์๋ค. ์ํผ์ค์~!
์ง๊ธ๊น์ง๋ javaScript๋ฅผ ์ด์ฉํด์ ์์์ ์ง์ ์คํ์ผ์ ํด์คฌ๋ค๋ฉด ์ด๋ฒ์ CSSํ์ผ์ ๋ง๋ค์ด์ importํด๋ณธ๋ค.
react์์์ css๋ ๊ฐ๊ฐ ๋ชจ๋ํํด์ ์ฌ์ฉํ ์ ์๊ธฐ๋๋ฌธ์ ํ์ผ๋ช
์ ์๋์ ๊ฐ์ด ๋ง๋ค์ด์ผ ํ๋ค.
//Button์ ์คํ์ผ์ ์ง์ ํ๋ cssํ์ผ์ ๋ง๋ ๋ค๊ณ ํ ๋
Button.moducle.css
.btn {
background-color: tomato;
color: white;
}
component์ ๋ง์ฐฌ๊ฐ์ง๋ก importํด์ ์ฌ์ฉํ๋ฉด ๋๋ค.
import styles from './Button.module.css';
function Button({ text }) {
return <button className={styles.btn}>{text}</button>;
}
export default Button;

ํ ๋งํ ์์ ๋ฒํผ์ด ๋ณด์ฌ์ง๋ค.
๋ด ๊ฒฝ์ฐ๋ App.module.css๋ ๋ง๋ค์ด์ App.js์ ์ ์ฉ์์ผ๋์ ์ํ์ด๋ค.
์ฌ๊ธฐ์ ๊ฐ๋ฐ์๋ชจ๋์ ์์๋ฅผ ํ์ธํด๋ณด๋ฉด

ํด๋์ค๋ช
์ด ์ปดํฌ๋ํธ๋ช
-ํด๋์ค๋ช
-๋๋ค๋ฌธ์ํ์์ผ๋ก ์ด๋ฃจ์ด ์ง ๊ฒ์ ๋ณผ ์ ์๋๋ฐ, ์ ๋๋ค๋ฌธ์ ๋๋ถ์ ๋ค๋ฅธ ์ปดํฌ๋ํธ์์ ๋์ผํ ํด๋์ค๋ช
์ด ์ฌ์ฉ๋์ด๋ ์คํ์ผ์ด ๊นจ์ง๋ ์ผ ์์ด ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.