Giter VIP home page Giter VIP logo

Comments (2)

AlexBSoft avatar AlexBSoft commented on June 5, 2024 2

I was facing the same problem. Current installation steps are invalid for Remix 2.8.1.

I managed to fix the problem:

  1. Install preline npm install preline

  2. Add the path to Preline UI JavaScript files in your tailwind.config.js file.

// tailwind.config.js
module.exports = {
  content: [
      './node_modules/preline/preline.js',
  ],
  plugins: [
      require('preline/plugin'),
  ],
}
  1. Create preline.client.tsx file for example in ~/components folder. (We will use client module):
import {
    useLocation,
} from "@remix-run/react";
import { useEffect } from "react";

import { IStaticMethods } from "preline/preline";
declare global {
    interface Window {
        HSStaticMethods: IStaticMethods;
    }
}

export default function PrelineScript() {
    const location = useLocation();

    useEffect(() => {
        import("preline/preline");
    }, []);

    useEffect(() => {
        setTimeout(() => {
            window.HSStaticMethods.autoInit();
        }, 100);
    }, [location.pathname]);

    return null;
}
  1. Connect this file in root.tsx:
...
// Import at top of file
import PrelineScript from "~/components/preline.client";

export function Layout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <Meta />
        <Links />
      </head>
      <body>
        {children}
        <ScrollRestoration />
        <Scripts />
        {/* Add preline script on every page */}
        {PrelineScript && <PrelineScript />}
      </body>
    </html>
  );
}

...

from preline.

bluefire2121 avatar bluefire2121 commented on June 5, 2024

`declare global {
interface Window {
HSStaticMethods: IStaticMethods;
}
}
if (typeof window !== "undefined") {
await import('preline/preline');
}

export function Layout({ children }: { children: ReactNode }) {
const location = useLocation();

useEffect(() => {
window.HSStaticMethods.autoInit();
}, [location.pathname]);

return ( ... )
`

Replace typeof window !== "undefined" with typeof document !== "undefined" to handle runtimes outside of Node like Deno. Read the Remix Gotchas for more info.

from preline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.