export const App = () => {
return (
<>
<h1>こんにちは!</h1>
<p>お元気ですか</p>
<button onClick={()=> alert()}>ボタン</button>
</>
);
};
export const App = () => {
const onClickButton = () => alert();
return (
<>
<h1>こんにちは!</h1>
<p>お元気ですか</p>
{console.log('hoge')}
<button onClick={onClickButton}>ボタン</button>
</>
);
};
export const App = () => {
return (
<>
<h1>こんにちは!</h1>
<p>お元気ですか</p>
{console.log("hoge")}
<button onClick={()=> alert()}>ボタン</button>
</>
);
};
export const App = () => {
const onClickButton = () => alert();
return (
<>
<h1 style=>こんにちは!</h1>
<p>お元気ですか</p>
{console.log('hoge')}
<button onClick={onClickButton}>ボタン</button>
</>
);
};
export const App = () => {
const onClickButton = () => alert();
const contentStyle = { color: 'blue', fontSize: '18px' };
return (
<>
<h1 style={contentStyle}>こんにちは!</h1>
<p>お元気ですか</p>
{console.log('hoge')}
<button onClick={onClickButton}>ボタン</button>
</>
);
};
import { ColorfulMessage } from './components/ColorfulMessage';
export const App = () => {
const onClickButton = () => alert();
const contentStyleA = { color: 'blue', fontSize: '18px' };
const contentStyleB = { color: 'green', fontSize: '18px' };
return (
<>
<h1 style={contentStyleA}>こんにちは!</h1>
<ColorfulMessage color="blue" message="お元気ですか?" />
<ColorfulMessage color="green" message="元気です!" />
<button onClick={onClickButton}>ボタン</button>
</>
);
};
export const ColorfulMessage = (props) => {
const contentStyleA = {
color: props.color,
fontSize: '18px',
};
return <p style={contentStyleA}>{props.message}</p>;
};
import { ColorfulMessage } from './components/ColorfulMessage';
export const App = () => {
const onClickButton = () => alert();
const contentStyleA = { color: 'blue', fontSize: '18px' };
const contentStyleB = { color: 'green', fontSize: '18px' };
return (
<>
<h1 style={contentStyleA}>こんにちは!</h1>
// ColorfulMessageで囲む。
<ColorfulMessage color="blue">お元気ですか?</ColorfulMessage>
<ColorfulMessage color="green">元気です!</ColorfulMessage>
<button onClick={onClickButton}>ボタン</button>
</>
);
};
export const ColorfulMessage = (props) => {
const contentStyleA = {
color: props.color,
fontSize: '18px',
};
// props.childrenでColorfulMessageで囲っている中のものを取得することができる。
return <p style={contentStyleA}>{props.children}</p>;
};
export const ColorfulMessage = (props) => {
const contentStyleA = {
color: props.color,
fontSize: '18px',
};
return <p style={contentStyleA}>{props.children}</p>;
};
export const ColorfulMessage = ({ color, children }) => {
// この分割代入でもOK
const {color, children} = props
const contentStyleA = {
color,
fontSize: '18px',
};
return <p style={contentStyleA}>{children}</p>;
};