Skip to content

Example shows invalid types #4

@ImLunaHey

Description

@ImLunaHey

Following the example for useDidChange from the README doesn't seem to work. It looks like there might be a type mismatch. 🤔

The null we can easily fix with prevProps?.[0].value !== props.value, it's the callback not matching that I'm stuck on.

export const Example: React.FC<{ value: number }> = (props) => {
  // Called when dependencies change, we can inspect previous dependencies
  useDidChange(
    // Argument of type '(prevProps: PropsWithChildren<{ value: number; }>[] | null) => void' is not assignable to parameter of type 'VoidFunction | ((previousDependencies: PropsWithChildren<{ value: number; }>[] | null) => VoidFunction)'.
    // Type '(prevProps: PropsWithChildren<{ value: number; }>[] | null) => void' is not assignable to type 'VoidFunction'.
    // Target signature provides too few arguments. Expected 1 or more, but got 0.
    // @ts-expect-error
    (prevProps) => {
      // 'prevProps' is possibly 'null'
      // @ts-expect-error
      if (prevProps[0].value !== props.value) {
        // ...
      }
    },
    [props],
    true
  );

  return <div>Test..</div>;
};

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