Skip to content

Instantly share code, notes, and snippets.

@mattgperry
Created January 16, 2025 10:32
Show Gist options
  • Save mattgperry/dbe63b9e1f51cd5e30d21dfd6fcd4a23 to your computer and use it in GitHub Desktop.
Save mattgperry/dbe63b9e1f51cd5e30d21dfd6fcd4a23 to your computer and use it in GitHub Desktop.
An example of modern Framer override APIs
import type { ComponentType } from "react"
import { createStore } from "https://framer.com/m/framer/store.js@^1.0.0"
const useStore = createStore({
myVariant: "A"
})
export function withSetVariant(Component): ComponentType {
return (props) => {
const [variant, setVariant] = useStore()
return <Component {...props} onClick={() => setVariant({ myVariant: "B" })} />
}
}
export function withMyVariant(Component): ComponentType {
return (props) => {
const [variant] = useStore()
return <Component {...props} variant={variant} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment