UNPKG

reakit-system

Version:

Reakit System utils

34 lines (33 loc) 1.09 kB
import * as React from "react"; /** * Custom hook that will call `children` if it's a function. If * `useCreateElement` has been passed to the context, it'll be used instead. * * @example * import React from "react"; * import { SystemProvider, useCreateElement } from "reakit-system"; * * const system = { * useCreateElement(type, props, children = props.children) { * // very similar to what `useCreateElement` does already * if (typeof children === "function") { * const { children: _, ...rest } = props; * return children(rest); * } * return React.createElement(type, props, children); * }, * }; * * function Component(props) { * return useCreateElement("div", props); * } * * function App() { * return ( * <SystemProvider unstable_system={system}> * <Component url="url">{({ url }) => <a href={url}>link</a>}</Component> * </SystemProvider> * ); * } */ export declare const useCreateElement: <T extends React.ElementType<any>>(type: T, props: Record<string, any>, children?: React.ReactNode) => JSX.Element;