However, while the component renders, the file select window does not pop up when it is being clicked. Has anyone successfuly integrated the File Upload functionality into their Nextjs project and is willing to share how they did it?
This is my Preline Script which is loaded through the layout.tsx of my app directory
`"use client";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
import { IStaticMethods } from "preline/preline";
declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
export default function PrelineScript() {
const path = usePathname();
I am looking to add the Preline File Upload to my Nextjs React project with reference to https://preline.co/plugins/html/file-upload.html https://preline.co/docs/file-upload.html
I make some changes from the html provided to convert to jsx and make use of dangerouslySetInnerHTML to resolve the hydration issue of https://github.com/facebook/react/issues/19932
However, while the component renders, the file select window does not pop up when it is being clicked. Has anyone successfuly integrated the File Upload functionality into their Nextjs project and is willing to share how they did it?
This is my Preline Script which is loaded through the layout.tsx of my app directory `"use client";
import { usePathname } from "next/navigation"; import { useEffect } from "react";
import { IStaticMethods } from "preline/preline";
declare global { interface Window { HSStaticMethods: IStaticMethods; } }
export default function PrelineScript() { const path = usePathname();
useEffect(() => { const loadPreline = async () => { const preline = await import("preline/preline"); const fileUpload = await import("@preline/file-upload"); const dropzone = await import("dropzone"); const lodash = await import("lodash"); // Import Preline Components here const { HSDropdown } = preline; const HSFileUpload = fileUpload.default; if ( typeof window !== "undefined" && typeof document .getElementById("data-hs-tab") ?.getAttribute("data-hs-tab") !== "undefined" ) { window.HSStaticMethods.autoInit(); // Initialise Preline Components here HSDropdown.autoInit(); HSFileUpload.autoInit(); } };
}, [path]);
return null; } `
This is my FileUpload Component
`const FileUploadComponent = () => { return ( <div id="hs-file-upload-with-limited-file-size" className="space-y-2" data-hs-file-upload='{ "url": "/upload", "maxFilesize": 1, "extensions": { "default": { "class": "shrink-0 size-5" }, "xls": { "class": "shrink-0 size-5" }, "zip": { "class": "shrink-0 size-5" }, "csv": { "icon": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4\"/><path d=\"M14 2v4a2 2 0 0 0 2 2h4\"/><path d=\"m5 12-3 3 3 3\"/><path d=\"m9 18 3-3-3-3\"/>", "class": "shrink-0 size-5" } } }'
Resolved for anyone interested in the solution:
`"use client";
import { usePathname } from "next/navigation"; import { useEffect } from "react";
import { IStaticMethods } from "preline/preline"; import Dropzone from "dropzone";
declare global { interface Window { HSStaticMethods: IStaticMethods; Dropzone: typeof Dropzone; } }
export default function PrelineScript() { const path = usePathname();
useEffect(() => { const loadPreline = async () => { const preline = await import("preline/preline"); await import("lodash"); // Import Preline Components here const { HSDropdown } = preline;
}, [path]);
return null; } `