💡 Node.js를 이용해서
create-react-app
을 만드는 방법을 공부해 보자
npx
를 타이핑 해서 저런 식으로 나오면 잘 되고 있는 것이다.npx
가 어디에 쓰는 것인지는 따로 찾아보고 정리해야겠다.npx create-react-app 폴더명
폴더명은 자기가 하고싶은거 임의로 정하면되고, 설치가 될 때 까지 기다린다.npm start
라고 명령어를 입력한다.App.js
와 index.js
만 남기고 다 삭제해 주었다.<Button />
생성import propTypes from 'prop-types';
function Button({text}) {
return <button>{text}</button>
}
Button.propTypes = {
text: propTypes.string.isRequired,
}
// 외부로 export하기 위한 문장
export default Button;
Button.js
파일을 생성 후 -> Button
컴포넌트를 만들어 주었다.export default Button;
문장을 작성해 줘야한다.import Button from "./Button";
function App() {
return (
<div>
<h1>Welcome back!!!</h1>
<Button text={'Continue'} />
</div>
);
}
export default App;
App.js
div태그 안에 Button 컴포넌트를 추가해준다.npm i prop-types
라고 작성하면 설치가 된다.import propTypes from 'prop-types';
Button.js
파일 젤 상단에 위에 코드를 적어준다.Button.propTypes = {
text: propTypes.string.isRequired,
}
import propTypes from 'prop-types';
function Button({text}) {
return (
<button style={{
backgroundColor: "tomato",
color: "white",
}}>{text}</button>
);
}
Button.propTypes = {
text: propTypes.string.isRequired,
}
// 외부로 export하기 위한 문장
export default Button;
<Button />
이라는 컴포넌트를 쓰면 다 똑같은 CSS만 써야하는 제한성이 생긴다..btn {
color: #fff;
background-color: tomato;
}
Button.module.css
파일을 생성해주고 위에 내용을 작성해준다.Button.js
에 import 시켜준다.import styles from './Button.module.css'
className
속성에 저런식으로 작성하게 되면 해당 클래스를 가진 버튼만 스타일이 지정된다..title {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 18px;
}
.btn
과 .title
의 클래스 명을 같게 해도➕ 추가로 공부할 것
1.npx
가 무엇인지?