You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
im using the Preline Stepper in a React + TypeScript project. I'm able to get an object back from HSStepper.getInstance(), but I'm running into a TypeScript error when I try to call the .goToNext() method on it.
When I call HSStepper.getInstance(), it successfully returns an object. However, when I try to call .goToNext() on that object, TypeScript gives me an error:
Property 'goToNext' does not exist on type 'ICollectionItem'.
I've checked the documentation and my type declarations, but I can't figure out the correct way to access the instance methods. Any help would be greatly appreciated.
Here is my setup:
Preline Initialization (App.tsx)
Preline is initialized globally and re-initializes on every route change.
// src/App.tsx
import { useEffect } from "react";
import { Outlet, useLocation } from "react-router";
async function loadPreline() {
return await import("preline/dist/index.js");
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
im using the Preline Stepper in a React + TypeScript project. I'm able to get an object back from HSStepper.getInstance(), but I'm running into a TypeScript error when I try to call the .goToNext() method on it.
When I call HSStepper.getInstance(), it successfully returns an object. However, when I try to call .goToNext() on that object, TypeScript gives me an error:
Property 'goToNext' does not exist on type 'ICollectionItem'.
I've checked the documentation and my type declarations, but I can't figure out the correct way to access the instance methods. Any help would be greatly appreciated.
Here is my setup:
Preline is initialized globally and re-initializes on every route change.
// src/App.tsx
import { useEffect } from "react";
import { Outlet, useLocation } from "react-router";
async function loadPreline() {
return await import("preline/dist/index.js");
}
function App() {
const location = useLocation();
useEffect(() => {
const initPreline = async () => {
await loadPreline();
if (window.HSStaticMethods) {
window.HSStaticMethods.autoInit();
}
};
initPreline();
}, [location.pathname]);
return ;
}
export default App;
I've declared the types for Preline based on its package structure.
// src/types/global.d.ts
import type { IStaticMethods, HSStepper } from "preline/dist";
declare global {
interface Window {
HSStepper?: typeof HSStepper;
HSStaticMethods?: IStaticMethods;
}
}
export {};
....
if (window.HSStepper) {
window.HSStepper.getInstance("#data-hs-stepper").goToNext();
}
...
why?
Beta Was this translation helpful? Give feedback.
All reactions