-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flickity-extensions support (hash/fullscreen/etc) #120
Comments
You can use dynamic import. Next.js provide their own API: import dynamic from 'next/dynamic'
const hash = dynamic(
() => import('flickity-hash'),
{ ssr: false }
)
function Carousel() {
return (
<>
{hash &&
<Flickity options={{ hash: true }}>
<img id="cat1" alt="" src="https://placeimg.com/640/480/animals" />
<img id="cat2" alt="" src="https://placeimg.com/640/480/animals" />
</Flickity>
}
</>
);
} Or you can do the in native javascript way const hash = typeof window !== 'undefined' ? import('flickity-hash') : () => null;
function Carousel() {
return (
<>
{hash &&
<Flickity options={{ hash: true }}>
<img id="cat1" alt="" src="https://placeimg.com/640/480/animals" />
<img id="cat2" alt="" src="https://placeimg.com/640/480/animals" />
</Flickity>
}
</>
);
} |
Thank you for your time, unfortunately that is what I am doing, and it doesn't seem to work, I have a codesandbox forked from your demo with the second method in it to show the behavior : https://codesandbox.io/s/react-flickity-fullscreen-p1lut Am I missing something ? I also did it with flickity-hash, and poped-out the window to see if it has an impact , I'm running out of ideas. |
https://codesandbox.io/s/react-flickity-fullscreen-forked-bpog8?file=/src/index.js
|
My bad I shared the wrong Codesanbox link, Actual behavior :
Expected behavior :
I provided another codesandbox link (in fact, it's the original one I failed to sent you), https://codesandbox.io/s/issue-pinpoint-flickity-plugins-oyql4?file=/pages/subdir/index.js My guess is it has to do with the load-order of plugins and flickity. I think if we could find what behavior is different between these sandboxes, we will find the issue. As always, thank you for your time. |
I suspect this is because how codesandbox works. I copied the project locally and it always works. Can u try that? |
Hello, I'm having trouble getting flickity-hash to work,
based on the codesandbox link you provide, if I just add
{hash: true}
it prints :Type '{ hash: boolean; }' is not assignable to type 'FlickityOptions')
see: https://codesandbox.io/s/flickity-hash-support-2kljx?file=/pages/index.tsx
EDIT: found #38 , which sounds like the same "issue",
Its about loading a flickity-addon.
But in my case, since I'm using next (static), I keep getting
ReferenceError: window is not defined
Do you know any workaround for this ?
Thanks
The text was updated successfully, but these errors were encountered: