Comments (11)
Hi!
Please check out the official documentation here Preline - Next.js
You should add the following code to prevent TS warnings:
import { IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
from preline.
Try setTimeout to 200? or something like this
useEffect(() => {
if (document.readyState === 'complete') {
window.HSStaticMethods.autoInit()
}
}, [path])
from preline.
I see many of us are getting confused by HSStaticMethods
.
It's just a way of saying that you need to import HS (eg.: HSAccordion) and call autoInit
on its instance.
Here's the PrelineLoader.jsx
from one of my (Next.js) projects:
"use client";
import HSAccordion from "@preline/accordion";
import { usePathname } from "next/navigation";
import { HSDropdown } from "preline/preline";
import { useEffect } from "react";
export default function PrelineLoader() {
const path = usePathname();
useEffect(() => {
import("preline/preline");
}, []);
useEffect(() => {
setTimeout(() => {
HSAccordion.autoInit();
HSDropdown.autoInit();
}, 100)
}, [path])
return <></>
}
I hope this helps. :)
from preline.
@VishalLudhrani So do I need to add HSDropdown instance if I want to ad the dropdown components? I'm still not getting them to work.
Yup. That is how it worked for me.
If you weren't able to get those to work, here's an alternative approach:
"use client";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
const isBrowser = typeof window !== undefined;
export default function PrelineLoader() {
const path = usePathname();
useEffect(() => {
if (isBrowser) {
// if this component is rendered on a browser, import preline
import("preline/preline");
}
}, [])
useEffect(() => {
setTimeout(() => {
if (isBrowser) {
// if this component is rendered on a browser, import relevant preline plugins
import("preline/preline").then(({ HSAccordion, HSDropdown, HSCollapse }) => {
HSAccordion.autoInit();
HSDropdown.autoInit();
HSCollapse.autoInit();
})
}
}, 100)
}, [path])
return <></>
}
from preline.
Also seeing this
from preline.
Also seeing this
from preline.
I'm facing the same issue.
from preline.
@VishalLudhrani So do I need to add HSDropdown instance if I want to ad the dropdown components? I'm still not getting them to work.
from preline.
I see many of us are getting confused by
HSStaticMethods
. It's just a way of saying that you need to import HS (eg.: HSAccordion) and callautoInit
on its instance.Here's the
PrelineLoader.jsx
from one of my (Next.js) projects:"use client"; import HSAccordion from "@preline/accordion"; import { usePathname } from "next/navigation"; import { HSDropdown } from "preline/preline"; import { useEffect } from "react"; export default function PrelineLoader() { const path = usePathname(); useEffect(() => { import("preline/preline"); }, []); useEffect(() => { setTimeout(() => { HSAccordion.autoInit(); HSDropdown.autoInit(); }, 100) }, [path]) return <></> }I hope this helps. :)
Hi can you please explain how HSAccordion
is related to HSStaticMethods
?
from preline.
@insivika HSStaticMethods
could be a placeholder (just a way to say your plugin would go here).
You would need to replace it with all the plugins you're using in your project.
So, in my case, I replaced it with HSAccordion
and HSDropdown
since I was using both.
[EDIT]:
This was just my assumption, which seemed to work for me.
from preline.
I see many of us are getting confused by
HSStaticMethods
. It's just a way of saying that you need to import HS (eg.: HSAccordion) and callautoInit
on its instance.
Here's thePrelineLoader.jsx
from one of my (Next.js) projects:"use client"; import HSAccordion from "@preline/accordion"; import { usePathname } from "next/navigation"; import { HSDropdown } from "preline/preline"; import { useEffect } from "react"; export default function PrelineLoader() { const path = usePathname(); useEffect(() => { import("preline/preline"); }, []); useEffect(() => { setTimeout(() => { HSAccordion.autoInit(); HSDropdown.autoInit(); }, 100) }, [path]) return <></> }I hope this helps. :)
Hi can you please explain how
HSAccordion
is related toHSStaticMethods
?
This Code is work for me ✨
from preline.
Related Issues (20)
- i.current is undefined when setTimeout to load HSStaticMethods.autoInit();
- Overlay Component Issues : public method & events not working HOT 1
- Issue: Some JavaScript behavior options are not functioning correctly, and there is a lack of precise documentation regarding their usage HOT 1
- Preline Dropdown only works after hard refresh HOT 7
- Instructions for Selecting an Option in HSSelect
- Documentation needs improvements regarding JS options & methods , with some options not working or lacking information!
- Steps on number input HOT 1
- collapse component not working on chrome, works in Firefox HOT 1
- Scrolling bug in the Scrollspy plugin in Chrome HOT 1
- Advanced Select Not displayed as expected in Nextjs HOT 1
- Vertically centered modals don't work HOT 3
- layout shift due to removal of scroll bar in browser HOT 2
- Second level dropdown does not work in firefox but does work in chrome HOT 1
- Search Issue with Non-Latin Characters in Select Plugin HOT 1
- Preline doesn't work with Solid.js and solid-start HOT 1
- Functions not working in React-Inertia project HOT 2
- javascript plugin not working HOT 1
- Preline Javascript plugin not working HOT 3
- Cannot dismiss opened Advanced Select controls while using FireFox HOT 3
- Unable to use Preline Examples in Remix App HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from preline.