Comments (5)
This issue is happening because the DOM is only available inside the browser client side and not server side. Nextjs is executing your code server side. To get around the error you can leverage nextjs dynamic imports feature and a react useEffect hook. This will ensure the DOM is available before importing scrollreveal
const MyComponent = () => {
const refToComponent = React.useRef(null)
useEffect(() => {
async function animate() {
if (refToComponent.current) {
const sr = (await import("scrollreveal")).default
sr().reveal(refToComponent.current)
}
}
animate()
}, [])
return (
<div ref={refToComponent}>HEY THERE!</div>
)
}
Hope this helps 😄
from scrollreveal.
If anyone facing the same issue, I have created a helper package to use Scrollreveal with Next.js. You can check out here.
from scrollreveal.
Hey @MQDXL , due to the nature of Next13/React 18 (Now React is a server side lib) -> you cannot grab elements from the DOM without specifying the 'use client'
at the top of the component/page. Also rather than this implementation you may consider next-reveal: https://github.com/ritmillio/next-reveal which provides you with a RevealWrapper for animating single elements and a RevealList to animate multiple items in a sequence.
from scrollreveal.
use sr().reveal(refToComponent.current, {reset: true}), scroll back to the revealed element, the animation can't animate again,
Do you have a solution to solve the bug?
const MyComponent = () => {
const refToComponent = React.useRef(null)
useEffect(() => {
async function animate() {
if (refToComponent.current) {
const sr = (await import("scrollreveal")).default
sr().reveal(refToComponent.current, {reset: true})
}
}
animate()
}, [])
return (
<div ref={refToComponent}>HEY THERE!</div>
)
}
from scrollreveal.
Hey @MQDXL , due to the nature of Next13/React 18 (Now React is a server side lib) -> you cannot grab elements from the DOM without specifying the
'use client'
at the top of the component/page. Also rather than this implementation you may consider next-reveal: https://github.com/ritmillio/next-reveal which provides you with a RevealWrapper for animating single elements and a RevealList to animate multiple items in a sequence.
@ritmillio thanks bro, I found my code error.that's the element's parent set height: 100%. say thanks to you again .
from scrollreveal.
Related Issues (20)
- SSL certificate for scrollrevealjs.org expired 2021-08-23 HOT 2
- CSS transition: all breaks reveal animations for elements visible on page load HOT 3
- Footer won't load HOT 1
- Cleanup option (and method) not working in v4.0.9 HOT 7
- Sveltekit: scrollreveal not working HOT 1
- ScrollReveal gets more and more delayed as you scroll
- Effect in the middle of the screen HOT 2
- Handling mid-page loads HOT 3
- Different Options on Subsequent Reveals?
- How to use elegantly in nuxt3? HOT 5
- Documentation on "Options"
- Repeat previous animation
- Add a copy clipboard button in installation snippets.
- Implement Dependabot to handle dependencies
- Whether to support left and right scrolling display animation
- ScrollReveal element disappears in a certain resolution
- ScrollReveal doesn't work with react-snap on first load, but after navigating with react-router to any page and come back again, is starts working on the same page
- Add a ScrollReveal().refresh(); method
- Viewport issue on slider
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 scrollreveal.