SolidJSS
SolidJS14mo ago
30 replies
Vex

Mass Normalization of Props

Hi all,
I find myself in the situation of wanting to provide non-reactive alternatives for some component props, i.e. allowing other devs to provide any of
interface SomeProps {
  foo?: Accessor<T> | T; // Accessor<T> | T | undefined
}

Currently, I've done this manually by; for any property x, of type T (literal), x = () => T.
Which in code is a whole lot of if statements.
Now, I could see how this could be a generic utility function - with support for providing defaults too, so does this exist already?
I'm aware of mergeProps, but that isn't exactly what I'm looking for. I'm also (now at least), aware of the babel pre-processing plugin, which seems handy enough, but I recon a function like the one described above would be pretty useful overall for allowing greater flexibility for all component props. Plugin or not.
Was this page helpful?