Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[renderHook] rerender with new props, new props are not consumed #964

Open
@alextrastero

Description

Passing new props to rerender doesn't work, please let me know if i'm doing anything wrong, thx

package.json

"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",

hook

export const useTriggerFocus = ({ condition = true, ref }: any): null => {
 console.log(condition);
 useEffect(() => {
 const element = ref.current;
 if (condition && element) {
 element?.focus();
 }
 }, [ref, condition]);
 return null;
};

test

 it('triggers a change', () => {
 const condition = false;
 const focus = vi.fn();
 const ref = {
 current: {
 focus,
 },
 };
 const { rerender } = renderHook(() => useTriggerFocus({ condition, ref }));
 rerender({ condition: true, ref: undefined });
 rerender();
 rerender();
 rerender();
 });
});

console

false
false
false
false
false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /