Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key attribute #73

Open
KapitanOczywisty opened this issue Oct 10, 2021 · 4 comments
Open

key attribute #73

KapitanOczywisty opened this issue Oct 10, 2021 · 4 comments

Comments

@KapitanOczywisty
Copy link
Contributor

KapitanOczywisty commented Oct 10, 2021

Currently key attribute is silently skipped, shouldn't this be set as attribute or property or at least in dataSet?

https://github.com/proteriax/jsx-dom/blob/a24e63e96836575ddf878a2a43263c7178c86db1/src/jsx-dom.ts#L135-L136

@Kir-Antipov
Copy link
Contributor

shouldn't this be set as attribute or property or at least in dataSet?

Nope, it should not:

Keys serve as a hint to React but they don’t get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name

source

@KapitanOczywisty
Copy link
Contributor Author

This is not react and key have to be accessible somehow to be any useful, for example to use with morphdom. Otherwise should be removed from types.

@alex-kinokon
Copy link
Owner

jsx-dom strikes to emulate React’s API and behavior as much as possible, that’s why key is stripped away.

@KapitanOczywisty
Copy link
Contributor Author

KapitanOczywisty commented Oct 11, 2021

And another thing to change in patch-package...

Completely removing key is wasteful, since it could be used with packages like morphdom, especially when somebody consciously adds key attribute to the code. Of course I could use id or class or dataset, but 1. this is inconvenient 2. some tools like eslint have special rules for key. Keeping key as at least dataset['jsxKey'] or data-jsx-key would make way more sense than silently throwing it away. Same goes for capture variants of events - PR is waiting for feedback.

jsx-dom strikes to emulate React’s API and behavior as much as possible

However some additional features are present, this could be one of them.

Edit:
In #17 you already accepted change to divert from react-like implementation, also for morphdom use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants