UNPKG

@wordpress/components

Version:
46 lines (41 loc) 1.16 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@wordpress/element"; /** * External dependencies */ // eslint-disable-next-line no-restricted-imports /** * Internal dependencies */ import { contextConnect } from '../context'; // eslint-disable-next-line no-duplicate-imports import { View } from '../view'; /** * Factory that creates a React component from a hook * * @param options * @param options.as The element to render for the component. * @param options.name The name of the component. * @param options.useHook The hook to use for the component * @param options.memo Whether to memo the component. * @return A polymorphic component that uses the hook to process props. */ export const createComponent = ({ as, name, useHook, memo = false }) => { function Component(props, forwardedRef) { const otherProps = useHook(props); return createElement(View, _extends({ as: as || 'div' }, otherProps, { ref: forwardedRef })); } Component.displayName = name; return contextConnect(Component, name, { memo }); }; //# sourceMappingURL=create-component.js.map