useState用法指南

1.引入

import React, {
    
     useState } from 'react'
  1. 使用
  const [count, setcount] = useState(0)
  1. 全部代码实现count加1
import React, {
    
     useState } from 'react'
export default function Example() {
    
    
  const [count, setcount] = useState(0)
  return (
    <div>
      <p>click me {
    
     count }</p>
      <button onClick={
    
    () => {
    
     setcount(count + 1)}}>+1</button>
    </div>
  )
}

猜你喜欢

转载自blog.csdn.net/weixin_45664217/article/details/123218866