vanta icon indicating copy to clipboard operation
vanta copied to clipboard

Halo doesn't work in React

Open mingcnjs opened this issue 4 years ago • 4 comments

I am getting this error when I import Halo. [VANTA] Init error TypeError: Cannot read property 'LinearFilter' of undefined

I tried the following codes.

import React, {useState, useEffect, useRef} from 'react' import * as THREE from 'three' import HALO from 'vanta/dist/vanta.halo.min'

const Vanta = props => { const [vantaEffect, setVantaEffect] = useState(0) const myRef = useRef(null) useEffect(() => { if (!vantaEffect) { setVantaEffect( HALO({ el: myRef.current, THREE: THREE, mouseControls: true, touchControls: true, gyroControls: false, minHeight: 200.0, minWidth: 200.0, }), ) } return () => { if (vantaEffect) vantaEffect.destroy() } }, [vantaEffect]) return

} export default Vanta

How can I resolve this error? [VANTA] Init error TypeError: Cannot read property 'LinearFilter' of undefined

mingcnjs avatar Nov 20 '20 03:11 mingcnjs

May I ask if you came up with a solution to this problem?

schmidfelix avatar Oct 06 '21 13:10 schmidfelix

I encountered the very same issue but couldn't find a solution yet. Would love to hear some feedback on this!

excalith avatar Nov 05 '21 17:11 excalith

Still same error here.

lucacv avatar Feb 06 '23 10:02 lucacv

I managed to solve this issue by loading threejs directly from _app.js. Not the most elegant solution, but seems to be working as intended. Example: https://cancellek.com

I think I have seen this solution on StackOverflow but couldn't find the link, so sharing the snippet.

    useEffect(() => {
        const threeScript = document.createElement("script");
        threeScript.setAttribute("id", "threeScript");
        threeScript.setAttribute(
            "src",
            "https://cdnjs.cloudflare.com/ajax/libs/three.js/r121/three.min.js"
        );
        document.getElementsByTagName("head")[0].appendChild(threeScript);
        return () => {
            if (threeScript) {
                threeScript.remove();
            }
        };
    }, []);

excalith avatar Feb 14 '23 07:02 excalith