Comments (29)
This is how I solved it
/_app.tsx
function MyApp({ Component, pageProps }: AppProps) {
useEffect(() => {
const use = async () => {
(await import('tw-elements')).default;
};
use();
}, []);
return <Component {...pageProps} />;
}
export default MyApp;
from tailwind-elements.
tried every thing the same problem
from tailwind-elements.
Hi Guys, for the nextjs
users you only need to create the _document.js
file with the next <Script/>
component
import { Html, Head, Main, NextScript } from 'next/document'
import Script from 'next/script'
// import 'tw-elements';
export default function Document() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
<Script src="./TW-ELEMENTS-PATH/dist/js/index.min.js"/>
</body>
</Html>
)
}
from tailwind-elements.
Hey, guys!
This is my approach with a NextJS 13 and new AppRouter.
- Create component for the initialisation of TWElements
"use client";
import { useEffect } from 'react';
export const TWElementsInit = () => {
useEffect(() => {
;(async () => (await import('tw-elements')))()
}, []);
return null
}
- Import into
app/layout.tsx
(which replaced the old one '_app.tsx')
import './globals.css'
import {TWElementsInit} from './tw'
export const metadata = {
title: 'Title,
description: 'description,
}
export default function RootLayout({
children,
}: { children: React.ReactNode
}) {
return (
<html lang="en">
<TWElementsInit/>
<body>{children}</body>
</html>
)
}
Good luck! :)
from tailwind-elements.
What you can do in the meantime is drag the index.min.js
(found in /node_modules/tw-elements/dist/js/
) into your static folder, then use this inside a custom layout (https://nextjs.org/docs/basic-features/layouts).
I personally put it inside a parent div, before the <main>{children}</main>
<Script src="index.min.js"/>
Although, I do not know if this is bad practice or not. The only thing I can think of is that you'll need to update the index.min.js inside your static folder yourself whenever it gets updated upstream.
from tailwind-elements.
@Trochonovitz link is broken btw
from tailwind-elements.
Hey, guys! This is my approach with a NextJS 13 and new AppRouter.
- Create component for the initialisation of TWElements
"use client"; import { useEffect } from 'react'; export const TWElementsInit = () => { useEffect(() => { ;(async () => (await import('tw-elements')))() }, []); return null }
- Import into
app/layout.tsx
(which replaced the old one '_app.tsx')import './globals.css' import {TWElementsInit} from './tw' export const metadata = { title: 'Title, description: 'description, } export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( <html lang="en"> <TWElementsInit/> <body>{children}</body> </html> ) }
Good luck! :)
and how do you init Carousel for example?
from tailwind-elements.
@Taarek this way we can have SSR ?
I'm not sure how to see that. I'm pretty new to the whole nextjs/react world.
I haven't ran into any issues at least from what I can tell.
from tailwind-elements.
finally solved the issue.
I added
import dynamic from "next/dynamic"
const {} = dynamic(import("tw-elements"), { ssr: false });
to the index.tsx file
which caused another error when deploying the website.
I solved that also by adding index.d.ts file to root
inside that file, I added
declare module "tw-elements"
line and also added "index.d.ts" to the include in tsconfig.json file
from tailwind-elements.
Hi, we just have launched bunch of integration tutorials - both with CSR and SSR frameworks. If you have more questions about integration or you still got some problems with particular components, let us know by adding new issue / topic in discussions section (if there are some unclrear informations or just want let us know about something).
from tailwind-elements.
Same here, I am assuming it's because of server-side rendering?
EDIT: duplicate of #1038 which is still unsolved since January
from tailwind-elements.
+1
from tailwind-elements.
@Taarek this way we can have SSR ?
from tailwind-elements.
+1
+1
I'll try what is suggested
from tailwind-elements.
This is how I solved it
/_app.tsx
function MyApp({ Component, pageProps }: AppProps) { useEffect(() => { const use = async () => { (await import('tw-elements')).default; }; use(); }, []); return <Component {...pageProps} />; } export default MyApp;
It worked like a charm.
Many thanks!
Really appreciated!!
It saved me more time spending on this.
😊 ❤️
from tailwind-elements.
This is how I solved it
/_app.tsx
function MyApp({ Component, pageProps }: AppProps) { useEffect(() => { const use = async () => { (await import('tw-elements')).default; }; use(); }, []); return <Component {...pageProps} />; } export default MyApp;
Yeah this works. This needs to be in the official documentation somewhere.
from tailwind-elements.
This is how I solved it
/_app.tsx
function MyApp({ Component, pageProps }: AppProps) { useEffect(() => { const use = async () => { (await import('tw-elements')).default; }; use(); }, []); return <Component {...pageProps} />; } export default MyApp;
thanks you so much dude @Adonis0123
from tailwind-elements.
Duplicate of #1044
@filipkappa @marveluck Any chance for a fix pretty please?
People are have started to resort to some very ridiculous workarounds for this issue.
from tailwind-elements.
useEffect(() => {
const use = async () => {
(await import('tw-elements')).default;
};
use();
}, []);
Worked perfectly! Thank you!
from tailwind-elements.
moi j'ai essayé toutes ces methodes mais ça ne marche toujours pas, je fais du nextt js
function MyApp({ Component, pageProps }: AppProps) {
useEffect (() => {
const use = async () => {
(await import('tw-elements')).default;
};
use();
}, []);
return <Component {...pageProps} />;
}
export default MyApp;
le code est souligné
from tailwind-elements.
Please, about this issue, i can not get my component to see the script js file, so it's not working properly any tw-elements component I am trying to use.
I did: in tailwind.config.js
content: [
"./pages//*.{js,ts,jsx,tsx}",
"./components//.{js,ts,jsx,tsx}",
"./src/**/.{html,js}",
"./node_modules/tw-elements/dist/js/**/*.js",
"./node_modules/react-tailwindcss-datepicker/dist/index.esm.js",
],
plugins: [require("tw-elements/dist/plugin"), require("@tailwindcss/forms")],
////
in _app.js i did:
useEffect(() => {
const use = async () => {
;(await import("tw-elements")).default
}
use()
}, [])
////
and finally i try to use some of the codein tw-elemts but they are not working
what am i doing wrong?
from tailwind-elements.
Tried everthing above, still no success, considering i'm using Next 13. Pls if someone find a better solution pls help.
from tailwind-elements.
Hi, we just have launched bunch of integration tutorials - both with CSR and SSR frameworks. If you have more questions about integration or you still got some problems with particular components, let us know by adding new issue / topic in discussions section (if there are some unclrear informations or just want let us know about something).
@Trochonovitz
The tutorial steps do not work. The components load but do not function. Also using import
with dynamic
gave a type error.
Type '() => Promise<typeof import("/.../pages/component.ts")>' is not assignable to type '() => LoaderComponent<{}>'.
Type 'Promise<typeof import("/.../pages/component.ts")>' is not assignable to type 'LoaderComponent<{}>'.
Type 'typeof import("/.../pages/component.ts")' is not assignable to type 'ComponentType<{}> | ComponentModule<{}>'.ts(2345)
```
from tailwind-elements.
@vforvasquez change your file extension to .tsx
instead of .ts
.
from tailwind-elements.
Hey, guys! This is my approach with a NextJS 13 and new AppRouter.
- Create component for the initialisation of TWElements
"use client"; import { useEffect } from 'react'; export const TWElementsInit = () => { useEffect(() => { ;(async () => (await import('tw-elements')))() }, []); return null }
- Import into
app/layout.tsx
(which replaced the old one '_app.tsx')import './globals.css' import {TWElementsInit} from './tw' export const metadata = { title: 'Title, description: 'description, } export default function RootLayout({ children, }: { children: React.ReactNode }) { return ( <html lang="en"> <TWElementsInit/> <body>{children}</body> </html> ) }
Good luck! :)
and how do you init Carousel for example?
Like so
export const TWElementsInit = () => {
useEffect(() => {
(async () => {
const { initTE, Carousel } = await import('tw-elements');
initTE({ Carousel });
})();
}, []);
return null;
};
from tailwind-elements.
Tried everything and nothing worked except for adding this code for every component I'm creating:
"use client";
import { useEffect } from "react";
const AppSelect = () => {
useEffect(() => {
const init = async () => {
const { Select, initTE } = await import("tw-elements");
initTE({ Select });
};
init();
}, []);
return (
<>
<select data-te-select-init multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
<option value="7">Seven</option>
<option value="8">Eight</option>
</select>
<label data-te-select-label-ref>Example label</label>
</>
);
};
export default AppSelect;
from tailwind-elements.
Does anyone have a solution to this using SvelteKit??
from tailwind-elements.
@ignitehub-dev I've just run into this issue today in my SvelteKit project. Kudos to the guys above, a SvelteKit alternative to their NextJS code seems to work:
<script context="module">
import { onMount } from 'svelte'; // import onMount either here or in the next script
export function initTWE() {
onMount(async () => {
const { initTE, Select } = await import('tw-elements');
initTE({ Select });
});
}
</script>
and then
<script>
initTWE()
</script>
Not sure if it's stable but at least it stopped raising VITE SSR error.
Disclaimer: I'm not even a dev, just a PM learning some JS with Svelte :)
from tailwind-elements.
@IliaNikonorov i gave up on using TW-Elements as a js package. I found it not to interact nicely when trying to link actions between components with svelteKit. I migrated my project to use Skeleton.
from tailwind-elements.
Related Issues (20)
- Charts - remove dynamic import and build charts as a different module
- Chips (Chip and ChipsInput) - fix dispose method and `add.te.chips` event
- Select/Autocomplete - fix aria-expanded value toggling
- Autocomplete - fix issues with input focus after closing the dropdown on esc
- Popconfirm - fix: way of adding event listeners, `cancel` event and dispose method
- When use tw input inside tw collapse, notch does not get updated correctly HOT 1
- Rating - add inheritance via BaseComponent and fix dispose method
- Lightbox - update image source URLs across all examples
- [Form Input Custom Classes] [data-te-class-notch-leading-valid, middle and trailing not working in Nuxt 3] HOT 2
- [FORMS - SELECT and MODAL] [NOT PROPERLY WORKING] HOT 1
- License AGPL HOT 1
- Timepicker Allow Minutes Step instead of Increment HOT 1
- Datepicker Format to allow more date formats HOT 1
- [Angular integration] [ReferenceError: document is not defined] HOT 3
- [ComponenMobile terminal navigation style problemt name] [description of the issue] HOT 3
- [Angular] - Datepicker re-initialization not wroking HOT 2
- Registration on Site - registration not taking, pw reset not working HOT 8
- v2.0 missing components HOT 4
- Pro vs Free HOT 3
- [Select] Can't attach events to select's options when there are more than 2 selects HOT 1
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 tailwind-elements.