How to have data attribute on Custom component?
I want to do something like <Foo data-something = { 'hello' } />
How to provide data props ?
7 Replies
const Foo = (props) => <div data-value={props['data-value']} />
?But I don't know it will be 'data-value', it can be data-anything like we do in plain <div>
How can't you know something that's going to be passed to Foo? unless you're spreading
in which case you spread it to the div too
I'm making generic component which can get any data attribute. Isn't it possible?
It's possible, but if you don't know the props its going to receive then you just spread it
const Foo = (props) => <div {...props} />
But using {...props} will add all other props doesn't need to be custom attribute in div.
then just select which one to not spread using
splitProps
or probably omitProps
from solid-primitives
or solid-use