const Button = ({ text, color, children }) => {
return (
<button
onClick={() => console.log(text)} // Event Handler
style={{ color: color }}
>
{text} - {color.toUpperCase()}
{children}
</button>
);
};
Button.defaultProps = {
color: 'white',
};
export default Button;
or
const Button = ({ text, color, children }) => {
const onClickButton = () => console.log(text);
return (
<button style={{ color: color }} onClick={onClickButton}>
{text} - {color.toUpperCase()}
{children}
</button>
);
};
Button.defaultProps = {
color: 'white',
};
export default Button;
함수를 밖으로 뺀 후 Onclick() 함수 안에 함수명을 넣는 것도 가능
const Button = ({ text, color, children }) => {
const onClickButton = () => console.log(text);
return (
<button style={{ color: color }} onClick={onClickButton}>
{text} - {color.toUpperCase()}
{children}
</button>
);
};
Button.defaultProps = {
color: 'white',
};
export default Button;
const Button = ({ text, color, children }) => {
const onClickButton = () => console.log(text);
return (
<button style={{ color: color }} onClick={onClickButton()}>
{text} - {color.toUpperCase()}
{children}
</button>
);
};
Button.defaultProps = {
color: 'white',
};
export default Button;

이를 해결하고자 나타난 것이... 합성 이벤트죠.
합성 이벤트란 모든 브라우저의 이벤트 객체를 하나로 통일한 형태입니다.
합성 이벤트는 빠른 속도의 인터넷을 위해 합성 이벤트를 사용해야합니다.

그만 알아보죠...