Button.jsx
const Button = (props) => {
console.log(props)
return(
<>
<button style={{color : props.color}}>
{props.text} - {props.color.toUpperCase()}
</button>
</>
)
}
Button.defaultProps = {
color: "black",
}
export default Button;
App.jsx
import './App.css'
import Button from './components/Button'
// root 컴포넌트
function App() {
return (
<>
{/* 자식컴포넌트 */}
<Button text={"메일"} color={"red"}></Button>
<Button text={"카페"}></Button>
<Button text={"블로그"}></Button>
</>
)
}
export default App
Button.jsx
const Button = ({text,color}) => {
return(
<>
<button style={{color : color}}>
{text} - {color.toUpperCase()}
</button>
</>
)
}
Button.defaultProps = {
color: "black",
}
export default Button;
import './App.css'
import Button from './components/Button'
// root 컴포넌트
function App() {
const buttonProps = {
text: "메일",
color : "red",
a : 1,
b : 2,
c : 3,
}
return (
<>
{/* 자식컴포넌트 */}
<Button {...buttonProps}></Button>
<Button text={"카페"}></Button>
<Button text={"블로그"}></Button>
</>
)
}
export default App
728x90
'DEVELOPE > 앱개발시작하기' 카테고리의 다른 글
[20240507] 앱개발 시작하기 #17 | State (0) | 2024.05.07 |
---|---|
[20240507] 앱개발 시작하기 #16 | 이벤트 핸들링 (0) | 2024.05.07 |
[20240507] 앱개발 시작하기 #14 | JSX 시작하기 (0) | 2024.05.07 |
[20240505] 앱개발 시작하기 #13 | 리액트 파일 만들기 (1) | 2024.05.05 |
[20240505] 앱개발 시작하기 #12 (0) | 2024.05.05 |