
Research
/Security News
OpenAPI React Query Codegen Compromised in Mini Shai-Hulud npm Supply Chain Attack
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.
@huxy/use
Advanced tools
异步处理
const [result, updateResult] = useAsync({});
const update = useCallback(params => updateResult({res: fetchList({...commonParams, ...params})}, handleResult), []);
将图片 src 地址 改为 base64。
const Base64Image = ({src, ...rest}) => {
const url = useBase64(src);
return <img decoding="async" loading="lazy" {...rest} src={url} />;
};
可取消异步函数
const {cancelablePromise} = useCancelablePromise();
cancelablePromise(asyncFn, delay)
.then(res => {})
.catch(error => {});
点击区域外部时触发的事件
useClickAway(liRef, e => li.open && itemClick(e, li));
第一个参数为区域元素,第二个为点击区域外部时的回调函数。
useDebounce(fn, (delay = 60));
第一个参数为需要防抖的函数,第二个为防抖时间,默认 60ms。
延迟获取 state
const [delayOpen] = useDelayState(open, delay);
是否为第一次加载
const isFirst = useFirstMounted();
定时器
const [count, setCount] = useState(0);
const [stop, setStop] = useState(false);
const delay = 3000;
useInterval(
() => {
setCount(count + 1);
},
stop ? null : delay,
);
第一个参数为回调函数,第二个参数是延迟时间。当 delay 值为 null 或 false 时,会停止回调函数的执行。
上一个 state 值
const prevState = usePrevious(state);
requestAnimationFrame
const [state, setState] = useRaf({});
const state = useScroll(element);
传入监听滚动的元素,默认 window
返回 state 为滚动位置信息。
搜索函数
const [filterTree, setFilterTree] = useSearch(null, str2Dom);
setFilterTree(data, keyword, (fields = 'name'), (exact = false), (idKey = 'id'), (childKey = 'children'));
name,设为 null 则全局所有属性搜索状态管理
const [state, update, subscribe, clean] = useStore(name, initState);
input:
output:
可以自定义状态管理库:
const store = createStore();
const useStore = createContainer(store);
更新
const rerender = useUpdate();
rerender();
初次进入不执行,state 发生变更时执行。
useUpdateEffect(()=>{
...
return ()=>...;
},[state]);
const {width} = useWinResize();
// delay:节流时间
const state = useEleResize(ref, (delay = 250));
获取/设置 render 过程中的 ref。
const data = useCustomRef(0)();
FAQs
react hooks
The npm package @huxy/use receives a total of 149 weekly downloads. As such, @huxy/use popularity was classified as not popular.
We found that @huxy/use demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.

Security News
Socket joins more than 100 technology, cybersecurity, and financial organizations calling for a global surge in cyber defense.

Product
Enterprise security teams can now detect malware, credential theft, suspicious network activity, and risky updates across Microsoft Edge extensions.