oluwatunmiisheii / react-smart-conditional

Inspired by conditional rendering in vue js, easily manage conditional rendering in react js. No more nested tenary operators.
MIT License
2 stars 0 forks source link

The default wrapper could be made a fragment instead of a div #4

Open Hussein-miracle opened 3 hours ago

Hussein-miracle commented 3 hours ago

It would make the components (If and Else) work better without affecting the styling, just like v-if,v-else works.

Would probably send a PR when i have the opportunity

oluwatunmiisheii commented 3 hours ago

Oh, made it like that so as to support polymorphism, you can pass in as={any valid component}

it.each<[string, React.ElementType, boolean | undefined]>([
  ['Show.If', Show.If, true],
  ['Show.Else', Show.Else, undefined],
])('renders %s as a custom element', (name, Component, condition) => {
  const { container } = render(
    <Show as="section">
      <Component
        {...(condition !== undefined ? { condition } : {})}
        as="span"
      >
        {name} content
      </Component>
    </Show>,
  );
  expect(container.firstChild?.firstChild?.nodeName).toBe('SPAN');
});