vtils

Home > react > useStateWithDeps

useStateWithDeps() function

给 useState 插上依赖的翅膀。依赖变化时会更新状态。

Signature:

export declare function useStateWithDeps<S>(state: S | (() => S), deps: React_2.DependencyList): [S, React_2.Dispatch<React_2.SetStateAction<S>>];

Parameters

Parameter Type Description
state S | (() => S) 状态
deps React_2.DependencyList 依赖

Returns:

[S, React_2.Dispatch<React_2.SetStateAction<S>>]

返回结果同 useState