Objective
This recipe demonstrates how to configure your Dojo 2 application to use JSX templating. Note, TSX is the TypeScript version of JSX.
Procedure
Rename your
Widget.ts/Widget.jsfile toWidget.tsx.Add the following configuration to your
tsconfig.jsonfile:
"include": [
"./src/**/*.ts",
"./src/**/*.tsx",
"./tests/**/*.ts"
]
- Add the
tsximport into your file:
import { tsx } from '@dojo/widget-core/tsx';
- Convert your
v()virtual DOM node function calls to use JSX:
Change this:
render() {
return (
v('div', [ 'Hello' ])
);
}
Into this:
render() {
return (
<div>
Hello
</div>
);
}
Additional resources
- The JSX Support section in the widget core documentation also covers how to use JSX templating in your Dojo 2 app
- JSX Documentation in the TypeScript handbook