项目
在 GitHub 查看
scottrippey/react-use-event-hook
关于
Same as React's useCallback, but returns a stable reference.
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- -1
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文react-use-event-hook
Same as React's useCallback, but returns a stable reference.
This library is a user-land implementation of the useEvent hook, proposed in this RFC.
Installation
npm install react-use-event-hook
Usage
(this example was copied from the RFC)
You can wrap any event handler into useEvent.
import useEvent from 'react-use-event-hook';
function Chat() {
const [text, setText] = useState('');
const onClick = useEvent(() => {
sendMessage(text);
});
return <SendButton onClick={onClick} />;
}
The code inside useEvent “sees” the props/state values at the time of the call.
The returned function has a stable identity even if the props/state it references change.
There is no dependency array.
See more
探索相关项目
加载中…