mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
Fix useArgs callbacks to have stable references
This commit is contained in:
parent
f2d90d1daa
commit
f7f4c1e950
@ -4,6 +4,7 @@ import React, {
|
||||
FunctionComponent,
|
||||
ReactElement,
|
||||
ReactNode,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
@ -437,12 +438,16 @@ export function useArgs(): [Args, (newArgs: Args) => void, (argNames?: string[])
|
||||
|
||||
const data = getCurrentStoryData();
|
||||
const args = isStory(data) ? data.args : {};
|
||||
const updateArgs = useCallback((newArgs: Args) => updateStoryArgs(data as Story, newArgs), [
|
||||
data,
|
||||
updateStoryArgs,
|
||||
]);
|
||||
const resetArgs = useCallback((argNames?: string[]) => resetStoryArgs(data as Story, argNames), [
|
||||
data,
|
||||
resetStoryArgs,
|
||||
]);
|
||||
|
||||
return [
|
||||
args,
|
||||
(newArgs: Args) => updateStoryArgs(data as Story, newArgs),
|
||||
(argNames?: string[]) => resetStoryArgs(data as Story, argNames),
|
||||
];
|
||||
return [args, updateArgs, resetArgs];
|
||||
}
|
||||
|
||||
export function useGlobals(): [Args, (newGlobals: Args) => void] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user