Sublime Forum

Auto close react component tag

#1

I’ve been working alot with react lately. Trying to to figure out how I can make sublime auto close component tag.

Something like this, press <Mycomponent> and sublime will autocomplete the </Mycomponent>

Is it possible to set it up like that?

0 Likes

#2

There’s the ALT+. binding that will close tags. It doesn’t always work, depending on nesting and such, but that might get you most of the way to what you want. For other tag-related commands, look in the Edit -> Tag menu.

0 Likes

#3

The built-in close command doesn’t work well for JSX tags. JS Custom provides a JSX-specific implementation that works much better. When you run the built-in close tag command, if the cursor is inside JSX code, then the JSX-specific command will be executed instead. In addition, JS Custom auto-closes JSX tags as you type. (All of this is configurable.)

0 Likes

#4

Triggering Emmet will auto-close tags, even within JSX. Type out your component/tag (no brackets, ie MyComponent), trigger Emmet, and it both wraps your component/tag in angle-brackets and closes component/tag.

0 Likes