<div id="app"></div>
function App (){
// ❌ Error!不符合 React Hooks 規範
function sayHi () {
const [count, setCount] = React.useState(0);
}
// ❌ Error!不符合 React Hooks 規範
if(true) {
const [count, setCount] = React.useState(0);
}
// ❌ Error!不符合 React Hooks 規範
for(let i = 0; i < 5; i += 1) {
const [count, setCount] = React.useState(0);
}
return (
<div>
<button type="button" onClick={ sayHi }>打招呼</button>
</div>
)
}
const app = document.querySelector('#app');
const root = ReactDOM.createRoot(app);
root.render(<App />);
View Compiled
This Pen doesn't use any external CSS resources.