Skip to content

String tag name as view #60

Closed
Closed

Description

@Kelin2025

Suppose we use pure elements instead of components for forms. We have to do

const SearchInput = reflect({
  view: (props: InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
  bind: { /* ... */ }
})

Could be just:

const SearchInput = reflect({
  view: "input",
  bind: { /* ... */ }
})

Activity

  1. AlexandrHoroshih commented on Mar 31, 2023

    @AlexandrHoroshih
    Member

    Is this actually a common case? 🤔

    I suppose, most of the times there will be some design anyway, which is better to build as a separate component without direct binding of the effector units

    Support for this feature will require somewhat complicated types and i'm not sure it is worth it

  2. added this to the v9.0 milestone on Jun 13, 2023
  3. Kelin2025 commented on Jun 13, 2023

    @Kelin2025
    MemberAuthor

    @AlexandrHoroshih answering your question - in order to do less view library-specific stuff (like refs forwarding, types etc.), Tailwind users sometimes don't create components but instead just compose classes and apply them to regular HTML elements
    So it can be like this:

    const NameField = reflect({
      view: 'input',
      bind: {
        className: inputEl
      }
    })

    And combined with some utilities

    const inputEl = cva("px-3 py-2", {
      variants: {
        size: {
          base: "text-base",
          large: "text-3xl"
        }
      }
    })
    
    const NameField = reflect({
      view: 'input',
      bind: {
        className: inputEl({ size: $inputSize })
      }
    })

    This way you have fully declarative, isomorphic code, which can be ported to any view library just by replacing cva and reflect imports

  4. AlexandrHoroshih commented on Dec 27, 2023

    @AlexandrHoroshih
    Member

    Released in 9.0.0 as fromTag helper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions