A note on JSX events (#2648)

Co-authored-by: Stephan Hoyer <ste.hoyer@gmail.com>
This commit is contained in:
Per Eriksson 2022-01-25 21:43:03 +01:00 committed by GitHub
parent 70aff8cd69
commit e66aaf1458
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,8 +2,10 @@
- [Description](#description) - [Description](#description)
- [Setup](#setup) - [Setup](#setup)
- [Production build](#production-build)
- [Using Babel with Webpack](#using-babel-with-webpack) - [Using Babel with Webpack](#using-babel-with-webpack)
- [JSX vs hyperscript](#jsx-vs-hyperscript) - [JSX vs hyperscript](#jsx-vs-hyperscript)
- [A note on event listeners](#a-note-on-event-listeners)
- [Converting HTML](#converting-html) - [Converting HTML](#converting-html)
--- ---
@ -23,6 +25,7 @@ function MyComponent() {
} }
// can be written as: // can be written as:
function MyComponent() { function MyComponent() {
return { return {
view: () => ( view: () => (
@ -338,6 +341,24 @@ function SummaryView() {
--- ---
### A note on event listeners
While JSX events are usually named using camelCase, lowercase names should be used when JSX is used with Mithril.
```jsx
m("main", [
m("input", { type: "text", oninput: ... }),
m("input", { type: "button", value: "Click me", onclick: ... })
])
// can be written as:
<main>
<input type="text" oninput={...}/>
<input type="button" value="Click me" onclick={...}/>
</main>
```
### Converting HTML ### Converting HTML
In Mithril, well-formed HTML is generally valid JSX. Little more than just pasting raw HTML is required for things to just work. About the only things you'd normally have to do are change unquoted property values like `attr=value` to `attr="value"` and change void elements like `<input>` to `<input />`, this being due to JSX being based on XML and not HTML. In Mithril, well-formed HTML is generally valid JSX. Little more than just pasting raw HTML is required for things to just work. About the only things you'd normally have to do are change unquoted property values like `attr=value` to `attr="value"` and change void elements like `<input>` to `<input />`, this being due to JSX being based on XML and not HTML.