{"id":18455723,"url":"https://github.com/danmarshall/tsx-create-element","last_synced_at":"2025-04-08T04:34:10.602Z","repository":{"id":47190669,"uuid":"146787661","full_name":"danmarshall/tsx-create-element","owner":"danmarshall","description":"Use TypeScript TSX without React","archived":false,"fork":false,"pushed_at":"2021-09-09T05:08:00.000Z","size":1044,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T15:27:37.078Z","etag":null,"topics":["jsx","tsx","typescript","typescript-tsx"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danmarshall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-30T18:05:26.000Z","updated_at":"2024-07-12T21:13:30.000Z","dependencies_parsed_at":"2022-09-14T17:42:42.222Z","dependency_job_id":null,"html_url":"https://github.com/danmarshall/tsx-create-element","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmarshall%2Ftsx-create-element","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmarshall%2Ftsx-create-element/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmarshall%2Ftsx-create-element/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmarshall%2Ftsx-create-element/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danmarshall","download_url":"https://codeload.github.com/danmarshall/tsx-create-element/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247779796,"owners_count":20994569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsx","tsx","typescript","typescript-tsx"],"created_at":"2024-11-06T08:08:50.921Z","updated_at":"2025-04-08T04:34:10.322Z","avatar_url":"https://github.com/danmarshall.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tsx-create-element\nUse TypeScript TSX without React\n\nLove the efficiency of TypeScript TSX syntax, but you have a small project that doesn't use React? This library may help.\n\n## Usage\n\n### createElement\nFirst, set your `tsconfig.json` file with these settings:\n```json\n{\n    \"compilerOptions\": {\n        \"jsx\": \"react\",\n        \"jsxFactory\": \"createElement\"\n    }\n}\n```\n\nThen create a file with the .tsx extension:\n```js\n//yourcomponent.tsx\nimport { createElement, StatelessProps } from 'tsx-create-element';\n\ninterface YourProps {\n    yourText: string;\n}\n\nexport const YourComponent = (props: StatelessProps\u003cYourProps\u003e) =\u003e {\n    return \u003cdiv\u003e{props.yourText}\u003c/div\u003e;\n}\n```\n\n### mount ( jsxElement: JSX.Element, container: HTMLElement )\nThis is analogous to [ReactDOM.render](https://reactjs.org/docs/react-dom.html#render). Typically your app will only `mount` one component which contains your entire tree. You will need to call `mount` anytime your props change. No React = no virtual DOM.\n\n```js\nimport { createElement, mount } from 'tsx-create-element';\nimport { YourComponent } from './yourcomponent';\nmount(YourComponent({yourText:\"hello world\"}), document.getElementById('your-div-ID'));\n```\n\n## Example code\nSee the [test folder](https://github.com/danmarshall/tsx-create-element/tree/master/test) for an example of component composition.\n\n## Caveats\n1. This will only render stateless components. No React = no React lifecycle.\n1. Everytime `mount` is called, the DOM subtree is obliterated. You may lose state in stateful elements such as textboxes. You will need to manage this yourself, prior to calling `mount`.\n1. You may also lose focus when `mount` is called. There is a [simplistic heuristic](https://github.com/danmarshall/tsx-create-element/blob/master/src/index.ts#L119) which tries to map the position of the [activeElement](https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/activeElement).\n1. A technique for maintaining stateful textboxes is found in [test/index.tsx](https://github.com/danmarshall/tsx-create-element/blob/master/test/index.tsx).\n\n## Test\nTo see the test page, run:\n\n```\nnpm start\n```\n\n## Similar work\n* https://yetawf.com/BlogEntry/Title/TypeScript%20and%20JSX%20without%20React/?BlogEntry=1034\n* https://holtwick.de/blog/jsx-without-react\n* https://www.meziantou.net/2018/05/28/write-your-own-dom-element-factory-for-typescript\n* https://github.com/dtkerr/jsx-no-react\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanmarshall%2Ftsx-create-element","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanmarshall%2Ftsx-create-element","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanmarshall%2Ftsx-create-element/lists"}