Jump to content
Search Community

Tried using useGSAP hook in framer for components

yahya_designer

Recommended Posts

yahya_designer
Posted

It might be platform specific that I can't import the useGSAP hook in there. Since I cant install packages in framer. I used the esm link
 

import { addPropertyControls, ControlType } from "framer"
import { motion } from "framer-motion"
import { useGSAP } from "https://cdn.jsdelivr.net/npm/@gsap/react@2.1.2/+esm"
 
export default function Gsap({ tint }) {
const { contextSafe } = useGSAP()    //think just crashes in preview
 
return (
 ////code here
)
}
I just get an error, so may its not possible or compatible with framer.
  • yahya_designer changed the title to Tried using useGSAP hook in framer for components
Posted

Hi,

 

Sorry to hear about the inconvenient 😞. Unfortunately I have zero experience with Framer so I can't really help.

 

I looked around and ask AI and got this:

Quote

Framer doesn't have an npm install step or a package manager panel. You add a package by importing it directly inside a code file, and Framer fetches it from a CDN as an ES module.

Steps

  1. Open the Assets panel, go to Code, and create a new code file. Choose either a Code Component or a Code Override.

  2. Import the package at the top of the file, the same way you would in any React project:

    import confetti from "canvas-confetti"
    

    Framer allows direct importing of npm packages as long as the package and all its dependencies are compliant with the JavaScript Module System.

  3. Use the package in your component. Then drag the component onto the canvas, or apply the override to an element.

Pinning a version. With a bare import, you don't have control over the version of the referenced package; once imported, updating to a newer version becomes impossible. To get around that, import from a full CDN URL instead:

import { Thing } from "https://esm.sh/[email protected]?external=react,react-dom"

The ?external=react,react-dom part matters. It makes the package use Framer's own copy of React, which avoids "invalid hook call" errors. This URL trick is also the fix when Framer's cache is stuck on an old version.

Common problems

  • CommonJS-only packages fail. These are packages that use require and have no ESM build. esm.sh usually converts them for you, so try the URL import first.
  • SSR errors. Framer renders your site on the server, so any package that touches window or document when it's imported or rendered can break the publish. Use it only inside useEffect or an event handler.
  • Node-only packages won't work at all. Anything that depends on fs, path, and similar modules can't run in the browser.

Sources:

 

 

Hopefully this helps somehow

Happy Tweening!

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...