I have used this library with React and TypeScript and created this typing definition to not have my compiler complain:
import { Component, ComponentLifecycle } from "react";
export declare function enableUniqueIds(component: Component): void;
export declare function resetUniqueIds(): void;
declare module "react" {
export interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> {
nextUniqueId(): string;
lastUniqueId(): string;
getUniqueId(identifier: string): string;
}
}
It is possible another interface would be a better spot for this, however I have used this with React.PureComponent and observed the expected results (i.e. an element had id="id-2-1").
I used it by manually adding the typing definition file to node_modules. Here is a class with this in use TransformedImagesElement/src/components/editor/inputs/SwitchInput.tsx. Manually adding it is not ideal, which leads to two possible solutions:
I have used this library with React and TypeScript and created this typing definition to not have my compiler complain:
It is possible another interface would be a better spot for this, however I have used this with
React.PureComponentand observed the expected results (i.e. an element hadid="id-2-1").I used it by manually adding the typing definition file to
node_modules. Here is a class with this in use TransformedImagesElement/src/components/editor/inputs/SwitchInput.tsx. Manually adding it is not ideal, which leads to two possible solutions: