import { ColorfulMessage } from './components/ColorfulMessage';
import { useState } from 'react';
export const App = () => {
const [num, setNum] = useState(0);
const onClickButton = () => {
setNum(num + 1);
};
const contentStyleA = { color: 'blue', fontSize: '18px' };
const contentStyleB = { color: 'green', fontSize: '18px' };
return (
<>
<h1 style={contentStyleA}>こんにちは!</h1>
<ColorfulMessage color="blue">お元気ですか?</ColorfulMessage>
<ColorfulMessage color="green">元気です!</ColorfulMessage>
<button onClick={onClickButton}>カウントアップ</button>
<p>{num}</p>
</>
);
};
import { ColorfulMessage } from './components/ColorfulMessage';
import { useState } from 'react';
export const App = () => {
const [num, setNum] = useState(0);
const onClickButton = () => {
// 実行すると+1しかされなかった。
setNum(num + 1);
setNum(num + 1);
};
const contentStyleA = { color: 'blue', fontSize: '18px' };
const contentStyleB = { color: 'green', fontSize: '18px' };
return (
<>
<h1 style={contentStyleA}>こんにちは!</h1>
<ColorfulMessage color="blue">お元気ですか?</ColorfulMessage>
<ColorfulMessage color="green">元気です!</ColorfulMessage>
<button onClick={onClickButton}>カウントアップ</button>
<p>{num}</p>
</>
);
};
import { ColorfulMessage } from './components/ColorfulMessage';
import { useState } from 'react';
export const App = () => {
const [num, setNum] = useState(0);
const onClickButton = () => {
setNum((prev) => prev + 1);
setNum((prev) => prev + 1);
};
const contentStyleA = { color: 'blue', fontSize: '18px' };
const contentStyleB = { color: 'green', fontSize: '18px' };
return (
<>
<h1 style={contentStyleA}>こんにちは!</h1>
<ColorfulMessage color="blue">お元気ですか?</ColorfulMessage>
<ColorfulMessage color="green">元気です!</ColorfulMessage>
<button onClick={onClickButton}>カウントアップ</button>
<p>{num}</p>
</>
);
};