OptionalWrapper
OptionalWrapper conditionally wraps children. When when is truthy, it returns wrapper(children). Otherwise it returns elseWrapper(children) or the original children. (fallback is accepted as a deprecated alias for elseWrapper.)
import { OptionalWrapper } from '@ilokesto/utilinent';
<OptionalWrapper
when={href}
wrapper={(children) => <a href={href}>{children}</a>}
>
Read more
</OptionalWrapper>Use it when the content should stay the same but its container changes, such as optional links, tooltips, feature-flag wrappers, or tracking wrappers.
With else transformer
<OptionalWrapper
when={enabled}
wrapper={(children) => <FeatureShell>{children}</FeatureShell>}
elseWrapper={(children) => <DisabledShell>{children}</DisabledShell>}
>
<FeatureContent />
</OptionalWrapper>fallback remains as a backward-compatible alias for elseWrapper.