Engineering from Scratch

エンジニア目指してます

2022-07-25から1日間の記事一覧

Updating Objects in State

Treat state as read-only import { useState } from "react"; function App() { const [plan, setPlan] = useState({ x: 1, y: 2 }); return ( <> {plan.x} <button onClick={() => (plan.x += 1)}>a</button> ); } export default App; 上記のコードでボタンを押下しても,画面に表示され…