How to fix code component errors in the Insert Menu preview
In March 2022, we made changes how the Insert Menu shows components.
The change was needed to support NPM packages in Framer and also improved performance and reliability. Components are shown exactly the same in the preview as in the final result.
Some components might show errors due to incorrect API usage that is no longer supported. For example, props.children
in a code component will no longer by an array, so should be accessed using React.Children
:
// Beforeconst childrenCount = props.children.length// Afterconst childrenCount = React.Children.count(props.children)
// Beforeconst firstChild = props.children[0]// Afterconst childrenArray = React.Children.toArray(props.children)const firstchild = childrenArray[0]// OR, when only one child is expectedconst firstChild = React.Children.only(props.children)
// Beforeprops.children.map(child => doSomething(child)) // AfterReact.Children.map(children, (child) => doSomething(child))