Skip to content

Instantly share code, notes, and snippets.

@fhur
Last active January 9, 2020 04:44
Show Gist options
  • Save fhur/7c155b09ffc5fea2ed10cc47122f2055 to your computer and use it in GitHub Desktop.
Save fhur/7c155b09ffc5fea2ed10cc47122f2055 to your computer and use it in GitHub Desktop.
How to reference design components with Framer X
// ================================
// Step 0:
// - Go to the canvas
// - Drop an image from your file system
// - Right click on the image and convert it to a design component
// - Rename the component to `Img1`
// ================================
import * as React from "react";
import { PropertyControls } from "framer";
// ================================
// Step 1: import the Img1 from ./canvas
// You can import any design component in your canvas, just make sure you reference it with the right name.
// ================================
import { Img1 } from "./canvas";
// Define type of property
interface Props {}
export class ImageComponent extends React.Component<Props, {}> {
static defaultProps = {};
static propertyControls: PropertyControls = {};
render() {
// ================================
// Step 2: Use the imported component. Make sure you use it as a JSX element, in particular DON'T do
// `return Img1` or `return new Img1` as they will simply not work.
// ================================
return <Img1 />;
}
}
@fhur
Copy link
Author

fhur commented Dec 10, 2018

screen shot 2018-12-10 at 10 21 14

As mentioned on Step one, make sure you name your component.

One small thing to remember:

If you name it as img1 (on the Framer X UI) (i.e. lower cased) you will anyway have to import it as Img1 (on the code). This is because by convention React components are PascalCased (see https://github.com/airbnb/javascript/tree/master/react#naming)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment