<a href="https://so.csdn.net/so/search?q=React&spm=1001.2101.3001.7020" target="_blank">React</a> Example babel</a>-standalone@6.15.0/babel.min.js"> type</a>="text/babel"></div><div> //创建一个Counter的组件</div><div> function Counter(){</div><div> const [count,setCount]=React.useState(0);//使用useState Hook来处处状态</div><div> function increment(){</div><div> setCount(count+1);//点击加一</div><div> }</div><div> function decrement(){</div><div> setCount(count-1);//点击减一</div><div> }</div><div> return(</div><div> <div></div><div> <h1>Counter:{count}</h1></div><div> <button onClick={increment}>➕</button></div><div> <button onClick={increment}>➖</button></div><div> </div></div><div> );</div><div> }</div><div> //渲染Counter组件到页面</div><div> ReactDOM.render(<Counter/>,document.getElementById('root'));</div><div> 上述基础react加一减一操作