0

I am using react hooks. I using a global context with reducer. Instead of writing each case of reducer function inside function. I want to separate in in the files. Example of my file is below

export type SetDrawingDataAction = {"set-drawing-data": Data};
export function setDrawingData(state : IGlobalState, data: number) : IGlobalState{

}

In the above file you can that I am using the name SetDrawingData at three places but with different formats.

Currently my snippet looks like below but its not making setDrawingDataAction capital.

"Generate Action file": {
  "prefix": "actd",
  "body": [
     "export type ${1/(.*)/${1:/capitalize}/} = {\"\": Data}",
     "export function $1(state : IGlobalState, data: Data) : IGlobalState {",
     "  $2",
     "}"
  ],
  "description": "Generate action file witn data"
} 

Kindly answer how can I change formats by using only single inputs. The first one is to capitalize the can second need is to change camelCase to camel-case

1 Answer 1

1

Assuming your input is setDrawingData try this snippet:

"Generate Action file": {
  "prefix": "actd",
  "body": [
     "export type ${1/(.*)/${1:/capitalize}/}Action = {\"${1/(.*)([A-Z][^[A-Z]*)([A-Z][^[A-Z]*)/$1-${2:/downcase}-${3:/downcase}/}\": Data}",
     "export function $1(state : IGlobalState, data: Data) : IGlobalState {",
     "  $2",
     "}"
  ],
  "description": "Generate action file witn data"
}

Here is the output of that snippet:

export type SetDrawingDataAction = {"set-drawing-data": Data}
export function setDrawingData(state : IGlobalState, data: Data) : IGlobalState {

}

snippet demo

Sign up to request clarification or add additional context in comments.

5 Comments

Not working for me. Do you press any key after typing setDrawingData?
You have to press tab after setDrawingData to complete the transform. Like a Variable-Transform, a transformation of a placeholder allows changing the inserted text for the placeholder when moving to the next tab stop. from code.visualstudio.com/docs/editor/… What that mean is that the transform happens when you go to the next or last stop.
I added a gif that shows the final tab that is necessary. You can either type setDrawingData as I did in the gif or paste it in - it doesn't matter.
Well no. maybe I am missing something obvious
Hmm, are you on v1.41 of vscode? What doesn't work? You can trigger the snippet? Type your setDrawingData, hit tab - what do you get?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.