I am trying to change background video on scroll, using react-intersection-observer. When inView changes to true, useEffect must change state to sample2, and send new video to startscreen, where it's using as background video with position fixed. State is changing, but video is still the same.
//Startscreen
const Startscreen = ({ sample }) => {
console.log(sample);
return (
<video className="videoTag" autoPlay loop muted>
<source src={sample} type="video/mp4" />
</video>
);
};
//App.js
import sample1 from "./videos/0.mov";
import sample2 from "./videos/2.mov";
function App() {
const [state, setState] = useState(sample1);
const { ref, inView, entry } = useInView({
threshold: 0.5,
});
useEffect(() => {
if (inView === true) {
setState(sample2);
} else {
setState(sample1);
}
console.log(state);
}, [inView]);
return (
<div className="App">
<Startscreen sample={state} />
<div ref={ref}>
<AboutMe>
</div>
</div>
)};