# Converting old tgui interfaces to tgui-next This guide is going to assume you already know roughly how tgui-next works, how to make new uis, etc. It's mostly aimed at helping translate concepts between tgui and tgui-next, and clarify some confusing parts of the transition. ## Backend Backend in almost every case does not require any changes. In particularly heavy ui cases, something to be aware of is the new `ui_static_data()` proc. This proc allows you to split some data sent to the interface off into data that will only be sent on ui initialize and when manually updated by elsewhere in the code. Useful for things like cargo where you have a very large set of mostly identical code. Keep in mind that for uis where *all* data doesn't need to be live updating, you can just toggle off autoupdate for the ui instead of messing with static data. ## Frontend The very first thing to note is the name of the `ract` file containing the old interface. Whatever the name is (minus the extension) is going to be what the route key is going to be. One thing I like to do before starting work on a conversion is screenshot what the old interface looks like so I have something to reference to make sure that the styling can line up as well. ## General syntax changes Ractive has a fairly different templating syntax from React. ### `data` You likely already know that React data inserts look like this ```jsx {data.example_data} ``` Ractive looks very similar, the only real difference is that React uses one paranthesis instead of two. ```ractive {{data.example_data}} ``` However, you may occasionally come across data inserts that instead of referencing the `data` var or things contained within it instead reference `adata`. `adata` was short for animated data, and was used for smooth number animations in interfaces. instead of having a seperate data structure for this. tgui-next instead uses a component, which is `AnimatedNumber`. `AnimatedNumber` is used like this ```jsx ``` Make sure you don't forget to import it. ### Conditionals Ractive conditionals look very different from React conditionals. A ractive `if` (only render if result of expression is true) looks like this ```ractive {{#if data.condition}} Example Render {{/if}} ``` The equivalent React would be ```jsx {!!data.condition && ( Example Render )} ``` This might look a bit intimidating compared to the reactive part but it's not as complicated as it seems: 1. A new jsx context is opened with `{}` 2. jsx contexts like this always render whatever the return value is, so we can use `&&` to return a value we want. `&&` returns the last true value (or not "falsey" because this is js). 3. jsx tags are never "falsey", so a conditioned paired with a jsx tag will mean the condition being true will continue on and return the tag. `()` is just used to contain the tag 4. The `!!` is not a special operator, it is a literal double negation. This is because most `false` values coming from byond are going to actually be `0`, which would be rendered if the condition is false. Negating `0` returns `true`, negating `true` returns `false`, which isn't rendered. 5. `Fragment` is actually a true "dead tag". It's similar to `span` in that it just contains things without providing functionality, but it's unwrapped before the final render and children of it are injected into its parent. In a case where you only need to render text without any styling, it's probably better to just return a string literal (`"Example Render"`), but this was just to illustrate that you can put any tag in this expression. You don't really need to know all this to understand how to use it, but I find it helps with understanding when things go wrong. Ractive conditionals can have an `else` as well ```ractive {{#if data.condition}} value {{else}} other value {{/if}} ``` Similarly to the previous example, just add a `||` operator to handle the "falsy" condition: ```jsx {!!data.condition && ( value ) || ( other value )} ``` There's also our good old friend - the ternary: ```jsx {data.condition ? 'value' : 'other value'} ``` Keep in mind you can also use tags here like the conditional example, and you can mix string literals, values, and tags as well. ```jsx {data.is_robot ? (