react-hooks-snippets
react-hooks-snippets copied to clipboard
Customize UseState Hook
Is there an option to customize the templates? For example, when I type 'ush + tab' I get:
const [ |, set|] = useState();
This is great. Thank you for creating this extension!
But this will not set the 'set' part in camelCase. If I wanted my const to be named 'foo' I would get:
const [foo, setfoo] = useState(); instead of const [foo, setFoo] = useState(); but my personal preference is actually
const [foo, fooSet] = useState();
Thanks again!
Hey @Brian-1150 , glad you like the extension!
At the moment, the ush snippet only supports const [foo, setFoo] = useState();
We've talked about adding custom settings in https://github.com/alDuncanson/react-hooks-snippets/issues/15, which can be done, but to do so the extension will have to be re-written in typescript.
I plan to do this, but it could take a while.
So, in the meantime I wrote a workaround for you:
- open the command palette and type
Preferences: Configure User Snippets - then select
New Global Snippets file... - paste the following:
"customUseState": {
"prefix": "<your-snippet-prefix>",
"body": [
"const [${1}, ${1}Set] = useState($2);$0"
],
"description": "React useState() hook"
}
- replace
<your-snippet-prefix>with the prefix you'd like to type to insert the snippet- ex
useState,customState, etc
- ex
- then save the file and you should be good to go!
Here's an example walkthrough: https://imgur.com/a/7C7GO9p
Thanks
Thanks
I no longer have the spare time to add new features to this extension, feel free to open a pr with the changes you'd like to see and I'll be happy to review it!