Skip to content

Conditional Wrap

Matt Layton edited this page Apr 13, 2020 · 2 revisions

ConditionalWrap is an abstraction which makes it simple to conditionally wrap content, whilst avoiding a duplicated definition of the content.

Usage

In this scenario the content would be wrapped inside a modal, but only for mobile devices.

<ConditionalWrap
  condition={isMobile}
  wrap={children => <Modal>{children}</Modal>}
  children={
    <p>Content here!</p>
  }
/>

API

Prop PropType Description
condition Bool! The condition to pass for children to be wrapped
wrap Fn! Render prop with children as the only argument. Invoked when the condition is true

Clone this wiki locally