-
Notifications
You must be signed in to change notification settings - Fork 164
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
In Next js 13.5 react-vertical-timeline not working #166
Comments
Have the same issue. It's an issue with animation. |
Same here! As @d-kunrath has suggested, this can be fixed by adding a visible="true" attribute to VerticalTimelineElement. In my case. using React.js/Next.js this is what the fixed code looked like:
|
That does make the content visible but stops the default animation of popping up VerticalTimelineElement as the component appears in the viewport. |
For "next": "13.4.8", it is working. |
The animation does not work for me either in next 13.5.2. I added animate={true} to VerticalTimelin, but this had no effect:
|
Yes the animation is not working @ananta-dev next 13.5.2 |
With next 13.5.2 is not working on local but when it's deploy I have no issue. |
Use inView() from react-intersection-observer |
Does this make the animation work? |
lovit it. thanks its working but let me know how did you find the solution? |
Hi @farrukh007 If you scroll down you will see: |
hi dear will you assist me one thing more about how may I resize the vertical timeline element? |
Hi @farrukh007 ! |
Actually, you can set it like this for react-vertical-timeline-component in Next.js 13.5, import { useInView } from "react-intersection-observer";
const { ref, inView } = useInView({
triggerOnce: true,
});
<section ref={ref}>
<VerticalTimeline lineColor="#e4e4e7">
{experiences.map((experience, index) => (
<VerticalTimelineElement
visible={inView}
date={experience.date}
icon={experience.icon}
key={index}... in this case, I only trigger the inView callback animation once. Hopefully it helps✌🏼 |
Thank you @diosetiad. That makes the animation work. That's great. However, with your solution the whole VerticalTimeLine is treated as a single block for the triggering of the animation. The whole timeline is animated at once. There are no individual animations for each VerticalTimeElement as we would expect. I have tried to generate individual refs for each element, even using the Do you have any idea how we may animate each VerticalTimelineElement individually, while maintaining the dynamic experiences.map structure? |
Here is the full solution. Ignore line 14 ( const { ref } = useSectionInView('Experience');). Need to use vissible={true} or useInViewfrom 'react-intersection-observer' to keep the animations.
|
Great job @SebastienRamsay! It works beautifully. For those who would prefer the animation to replay if the user scrolls back up and then down again, one can change this:
to this:
|
Question @SebastienRamsay
It appears eslint does not like me calling a hook from inside a callback. Did you have this issue when deploying? |
Update: I managed to get rid of the Vercel deployment eslint error by extracting the callback to a separate component, like this:
Credit to this Stackoverflow answer: Unfortunately (for me) the deployed version does not replay animation when the user scrolls back up to above the timeline and then down again to bring the timeline into view for a second time. Has anyone managed to get it to work after deploying? |
🤦 |
@ananta-dev sorry for replying now, we can animate each VerticalTimelineElement individually like this : import { VerticalTimelineElement } from "react-vertical-timeline-component";
import "react-vertical-timeline-component/style.min.css";
import { useInView } from "react-intersection-observer";
export default function TimelineElement({ item }) {
const { ref, inView } = useInView({
triggerOnce: true,
});
return (
<div ref={ref} className="vertical-timeline-element">
<VerticalTimelineElement
contentStyle={{
...
}}
contentArrowStyle={{
...
}}
date={item.date}
icon={item.icon}
iconStyle={{
...
}}
visible={inView}
>
<h4 className="font-semibold">{item.title}</h4>
<p className="!mt-0 font-normal">{item.location}</p>
<p className="!mt-1 !font-normal text-zinc-700 dark:text-white/75">
{item.description}
</p>
</VerticalTimelineElement>
</div>
);
} import TimelineElement to main component. "use client";
import { experiencesData } from "@/lib/data";
import { VerticalTimeline } from "react-vertical-timeline-component";
import TimelineElement from "./timeline-element";
export default function Experience() {
return (
<section
className="my-20 flex w-full scroll-mt-28 flex-col items-center justify-center gap-10"
id="#experience"
>
<VerticalTimeline lineColor="#e4e4e7">
{experiencesData.map((item, index) => {
return ( <TimelineElement key={index} item={item} /> );
})}
</VerticalTimeline>
</section>
);
} now the animation definitely works and there are no eslint errors. Hopefully it helps✌🏼 |
Yeah this stumped me, using hooks has to be at the top level of the component, so extracting it into a separate component worked like a charm like the solution you found! Glad we're all sharing this with each other, helps to see other perspectives for problem solving! |
I am facing the same issue in Next.js 14.0.3. Is this issue in the package or Next.js?? |
"use client"; import React from "react"; export default function Experience() { return ( My experience {experiencesData.map((item, index) => { return ( <React.Fragment key={index}> <VerticalTimelineElement contentStyle={{ background: theme === "light" ? "#f3f4f6" : "rgba(255, 255, 255, 0.05)", boxShadow: "none", border: "1px solid rgba(0, 0, 0, 0.05)", textAlign: "left", padding: "1.3rem 2rem", }} contentArrowStyle={{ borderRight: theme === "light" ? "0.4rem solid #9ca3af" : "0.4rem solid rgba(255, 255, 255, 0.5)", }} date={item.date} icon={item.icon} iconStyle={{ background: theme === "light" ? "white" : "rgba(255, 255, 255, 0.15)", fontSize: "1.5rem", }} > {item.title}{item.location}
</React.Fragment> ); })} ); } |
The content inside VerticalTimelineElement is not reflecting |
https://ricardo-portfolio-site.vercel.app/ |
same for me. |
I have next 13.5 but i get this problem: node_modules\react-intersection-observer\react-intersection-observer.js Caused by: |
you could just return the inView in your custom Hook |
yes you are right, but this animate the component as a whole since you have one and same inView prop for the all timeline elements. In order to animate timeline elements one by one, you need to follow @diosetiad recommendation. Its up to you how you'd like to animate |
For that I did And set visible=isInView because I faced the same problem. |
It worked for me even with next 14: // package.json
{
"name": "portfolio",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@react-email/components": "^0.0.7",
"@react-email/tailwind": "^0.0.8",
"@types/node": "20.3.2",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
"autoprefixer": "10.4.14",
"clsx": "^1.2.1",
"eslint": "8.43.0",
"eslint-config-next": "13.4.7",
"framer-motion": "^10.12.17",
"next": "14.1.0",
"postcss": "8.4.24",
"react": "^18",
"react-dom": "^18",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.10.1",
"react-intersection-observer": "^9.5.2",
"react-vertical-timeline-component": "^3.6.0",
"resend": "^0.16.0",
"tailwindcss": "3.3.2",
"typescript": "5.1.5"
},
"devDependencies": {
"@types/react-vertical-timeline-component": "^3.3.3"
}
} // vertical timeline component
"use client";
import React from "react";
import SectionHeading from "./section-heading";
import {
VerticalTimeline,
VerticalTimelineElement,
} from "react-vertical-timeline-component";
import "react-vertical-timeline-component/style.min.css";
import { experiencesData } from "@/lib/data";
import { useTheme } from "@/context/theme-context";
import { useInView } from "react-intersection-observer";
export default function Experience() {
const { theme } = useTheme();
const { ref, inView } = useInView({
triggerOnce: true,
});
return (
<section id="experience" ref={ref} className="scroll-mt-28 mb-28 sm:mb-40">
<SectionHeading>My experience</SectionHeading>
<VerticalTimeline lineColor="">
{experiencesData.map((item, index) => (
<React.Fragment key={index}>
<VerticalTimelineElement
visible={inView}
contentStyle={{
background:
theme === "light" ? "#f3f4f6" : "rgba(255, 255, 255, 0.05)",
boxShadow: "none",
border: "1px solid rgba(0, 0, 0, 0.05)",
textAlign: "left",
padding: "1.3rem 2rem",
}}
contentArrowStyle={{
borderRight:
theme === "light"
? "0.4rem solid #9ca3af"
: "0.4rem solid rgba(255, 255, 255, 0.5)",
}}
date={item.date}
icon={item.icon}
iconStyle={{
background:
theme === "light" ? "white" : "rgba(255, 255, 255, 0.15)",
fontSize: "1.5rem",
}}
>
<h3 className="font-semibold capitalize">{item.title}</h3>
<p className="font-normal !mt-0">{item.location}</p>
<p className="!mt-1 !font-normal text-gray-700 dark:text-white/75">
{item.description}
</p>
</VerticalTimelineElement>
</React.Fragment>
))}
</VerticalTimeline>
</section>
);
}
|
…ion timeline now works
You are not using |
using react-vertical-timeline-component library note: stephane-monnot/react-vertical-timeline#166 Had to set visible={true}, thus no animation
Thank you! |
Thanks @SebastienRamsay , this works well , and its is easy to impliment with next ! good job |
In Next js 13.5 react-vertical-timeline not working. content not visible
The text was updated successfully, but these errors were encountered: