App.js
import React from 'react';
import Hello from './Hello';
function App() {
return (
<div>
<Hello name='react' color="red"/>
</div>
);
}
export default App;
Hello.js
import React from 'react';
function Hello(props) {
console.log(props);
return <div style={{
color: props.color
}}>안녕하세요 {props.name}</div>;
}
export default Hello;
import React from 'react';
function Hello({color, name}) {
return <div style={{
color
}}>안녕하세요 {name}</div>;
}
export default Hello;
defaultProps (기본값)
import React from 'react';
function Hello({color, name}) {
return <div style={{
color
}}>안녕하세요 {name}</div>;
}
Hello.defaultProps = {
name: '이름없음'
};
export default Hello;