2

I have a snippet set like so:

import React from 'react'

const ${1:$$(file-name-base)} = ( ${2:$$(yas-choose-value '("\{ \}" "props"))} ) => {
  return (
    $0
)
}

export default $1

If I choose {}, the cursor moves to the right of it. After choosing {}, how do I place the cursor between the brackets, i.e {_}?


An example of a completed snippet:


import React from 'react'

const Notification = ({ message }) => {
  return (
    <div className='error'>
      {message}
    </div>
  )
}

export default Notification
2
  • I don't think we have enough context to answer this. Can you show how you expect the sinppet to expand. Also why are you using yas-choose-value with only one list item?
    – ocodo
    Commented Aug 21, 2022 at 13:04
  • @ocodo I forgot to add it back. I use the snippet to create an es6 module from a newly created file. I added an example of a completed one above.
    – mustaqim
    Commented Aug 21, 2022 at 15:04

1 Answer 1

1

Unfortunately yas-choose-value doesn't provide any additional magic to move your cursor into the braces.

The simplest and most flexible way to achieve what you want, is to use stacked expansion. In other words, another snippet expand while you're expanding this one, making it just $2

yas/triggers-in-field

This variable, when set to t will do just that, type the next snippet trigger and when it's done, you'll be returned to the original snippet. In your case at $0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.