// カウントするReactコンポーネント
function Counter() {
const [count, setCount] = useState(0)
return (
<span>
<div>
<h1>hello world!!</h1>
<div>クリック数: {count}</div>
<button onClick={() => setCount(count + 1)}>クリック</button>
</div>
</span>
)
}
// JSXをcreateElementに置き換えると
function Counter() {
const [count, setCount] = useState(0)
return React.createElement(
'span',
null,
React.createElement(
'div',
null,
React.createElement('h1', null, 'hello world!!'),
React.createElement('div', null, 'クリック数: ', count),
React.createElement(
'button',
{ onClick: () => setCount(count + 1) },
'クリック'
)
)
)
}
{
type: 'span',
props: {
// spanの中が1つの要素だけならchildrenがobjectになる
children: {
type: 'div',
props: {
// divの中が複数の要素ならchildrenが配列になる(要素が1つになるまで配列だと思う)
children: [
{
type: 'h1',
props: {
children: 'hello world!!',
},
},
{
type: 'div',
props: {
children: ['クリック数: ', count],
},
},
{
type: 'button',
props: {
onClick: () => setCount(count + 1),
children: 'クリック',
},
},
],
},
},
},
}
Fiberとは、React elementから作成されるReconcilerの最小の作業単位のこと。
Fiber ReconcilerでのReconciliation Flowは以下の通り
1.workLoop
2.Render phase
3.Commit phase
Fluent React: Build Fast, Performant, and Intuitive Web Applications