UNPKG

@zohodesk/utils

Version:

DOT Utils Collection

28 lines (24 loc) 913 B
import React, { isValidElement } from 'react'; /** * Utility function to render content that can be either a function or a React element * @param {Function|React.ReactElement|null|undefined} content - The content to render * @param {Object} props - Optional props to pass to the function if content is a function * @returns {React.ReactElement|null} - The rendered content or null */ export default function renderNode(content, props) { let result = content; if (typeof content === 'function') { result = content(props); } return /*#__PURE__*/isValidElement(result) ? result : null; } ; /** * Checks if the content is renderable (function or valid React element) * @param {any} content - The content to check * @returns {boolean} - True if content is renderable */ export function isRenderable(content) { return typeof content === 'function' || /*#__PURE__*/isValidElement(content); } ;