This talk has been presented at React Day Berlin 2023, check out the latest edition of this React Conference.
Video: Hacking JSX: Building in Minecraft with React
FAQ
JSX is a way of writing pseudo-HTML code within JavaScript code. It needs to be transpiled into something the browser can understand, typically a call to React's react.createElement() function.
A domain specific language (DSL) is a programming language designed to do one thing particularly well, unlike general-purpose languages like JavaScript that can solve any problem. Examples include SQL for databases and HTML for web page structure.
JSX can be used to create builds in Minecraft by converting JSX syntax into game commands. This involves creating a custom JSX handler function that converts the JSX into an array of objects or commands understood by the game.
There are two main reasons: 1) Familiarity with JSX means there is no steep learning curve, and 2) Existing tooling for JSX, such as parsers, linters, and IDE support, can be leveraged, eliminating the need to write custom tools.
The react.createElement() function is what JSX is transpiled into when using React. It converts JSX syntax into React elements that the browser can understand.
Yes, JSX can be used outside of React by using a custom function that has the same signature as react.createElement(). This allows for custom behavior and use cases.
The intermediary representation is a way to convert JSX syntax into a different format, such as an array of objects or classes. This format can vary depending on the problem being solved.
In Minecraft, blocks are placed using three coordinates: x, y, and z. Each block also has a type, defined by an ID value.
Using JSX for creating custom languages offers advantages like familiarity, reducing the learning curve, and leveraging existing tooling for parsing, linting, and IDE support.
The source code for the JSX Minecraft build project is available on GitHub.
Available in other languages:
Check out more articles and videos
We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career