react-hooks-me

react-hooks-me

Usage no npm install needed!

<script type="module">
  import reactHooksMe from 'https://cdn.skypack.dev/react-hooks-me';
</script>

README

描述

自定义的,第三方的,实用的 react hooks

安装

npm install react-hooks-me -S

usage

import React, { useState } from 'react'
import { useWatch } from 'react-hooks-me'

function App() {
  const [count, setCount] = useState(0)

  useWatch(count, (oldValue) => {
    console.log('count 改变了')
    console.log('count变化前:', oldValue)
    console.log('count变化后:', count)
  })

  return (
    <div>
      <div>{count}</div>
      <button onClick={() => setCount((pre) => pre + 1)}>add</button>
    </div>
  )
}

注意

只支持浅变化,不支持深层的对象属性的变化。