I tried to use typescript with jsx without react. and it doesn't work.
I always put a "jsx": "preserve"
in tsconfig.json.
But i dont understand what i have to do next.and when i am compiling .tsx file webpack throws an error
ERROR in ./core/Navbar.tsx
Module parse failed: /home/ubuntu/Desktop/framework/node_modules/ts-loader/index.js!/home/ubuntu/Desktop/framework/core/Navbar.tsx Unexpected token (9:15)
You may need an appropriate loader to handle this file type.
i read the documentation but i dont understand how to use global jsx module in project.
is it possible to use typescript + jsx without react?
my App.tsx class
[
error when webpack compile file
I just made this, maybe it could help
export const JSX = {
createElement(name: string, props: { [id: string]: string }, ...content: string[]) {
props = props || {};
const propsstr = Object.keys(props)
.map(key => {
const value = props[key];
if (key === "className") return `class=${value}`;
else return `${key}=${value}`;
})
.join(" ");
return `<${name} ${propsstr}> ${content.join("")}</${name}>`;
},
};
export default JSX;
declare module JSX {
type Element = string;
interface IntrinsicElements {
[elemName: string]: any;
}
}
"jsx": "react",
"reactNamespace": "JSX",
import JSX from "./index";
function Hello(name: string) {
return (
<div className="asd">
Hello {name}
<div> Hello Nested </div>
<div> Hello Nested 2</div>
</div>
);
}
function log(html: string) {
console.log(html);
}
log(Hello("World"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With