Closed tobySolutions closed 1 year ago
IMHO we shouldn't change the name h
as h
is widely used in many virtual dom or related libraries. Renaming it would cause more chaos.
Preact
https://preactjs.com/guide/v10/api-reference#h--createelement
import { h } from 'preact';
Vue.js
https://vuejs.org/api/render-function.html#h
import { h } from 'vue'
snabbdom
https://github.com/snabbdom/snabbdom#h
import { h } from 'snabbdom'
virtual-dom
https://github.com/Matt-Esch/virtual-dom
var h = require('virtual-dom/h');
Solid.js
https://www.solidjs.com/examples/simpletodoshyperscript
import h from "solid-js/h";
hyperscript
https://github.com/hyperhype/hyperscript
var h = require('hyperscript')
vobyjs
https://github.com/vobyjs/voby#h
import {h} from 'voby';
Thank you @SukkaW. @aidenybai rightly pointed that out to me. I'll close this issue now.
For CodeDay Labs students only, do not assign to anyone else
The function
h
in/million/packages/jsx-runtime/index.ts
has the following code:The above code is problematic and gives a bad developer experience because of the bad naming of
h
that it has.In the above block of code, we can see that we have a Typescript function that is meant to return a Virtual DOM node based on the parameters:
type
(type of dom element e.gp
,h1
, and so on),props
(like attributes of a React dom component whichchildren
is technically a part of) andchildren
(in this case the content of the component and what is being with dom element).The code above just returns something of the following format to us
h('div', { id: 'foo' }, 'hello')
which is actually<div id="foo">hello</div>
What we need to do are the following steps:
element
,domElement
orvirtualDomElement
)element
, I would have:export const element = ( type: string, props: Props | null = {}, ...children: VNode[] ): VNode => { if (props === null) props = {}; props.children = children; return { type, props, }; };