Skip to content

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

Open
@alextrastero

Description

@alextrastero

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