Switch.framerfx icon indicating copy to clipboard operation
Switch.framerfx copied to clipboard

Can't use Switch within Component

Open vermap0107 opened this issue 4 years ago • 1 comments

Everytime I try using "Switch" within a component, it throws this error Screenshot 2021-07-07 at 10 05 25 AM

vermap0107 avatar Jul 07 '21 04:07 vermap0107

I think the way framer sets transitions broke this component (again). I managed to fix it by adding an override to my variants:

import { ComponentType, cloneElement } from "react"

export function fixSwitch(Component): ComponentType {
    return ({ children, ...props }) => {
        const fixedVariants = children.map(
            (variant) =>
                variant &&
                cloneElement(variant, {
                    children: cloneElement(variant.props.children, {
                        transition: "instant", // Or whatever transition you want for the switch
                    }),
                })
        )

        return <Component {...props}>{fixedVariants}</Component>
    }
}

Note that if you have to apply the override to the variant layer and not the switch layer. Apologies but im new to framer and I dont completely understand the mental model

Joelkang avatar Mar 10 '22 14:03 Joelkang