VS CodeのスニペットでReactのコンポーネント雛形を作る
3965 ワード
コンポーネントの雛形をVS Codeのスニペットに登録しておくと捗ります♪
スニペットの設定手順
- VS Codeの
Code > Preferences > User Snippets
tsxファイルのスニペットを作る場合typescriptreact
と入力
VS Codeではスニペットをファイル種別ごとにjsonファイルで管理します。
以下をコピペ
以下はReact Nativeのコンポーネントの一例です。お好みで変更して下さい。
{
"React Native Component": {
"prefix": "react-native-component",
"body": [
"import React from \"react\";",
"import { View, StyleSheet } from \"react-native\";",
"",
"type Props = {};",
"",
"export const ${TM_FILENAME_BASE}: React.FC<Props> = ({}) => {",
"\treturn (",
"\t\t<View style={styles.container}>",
"\t\t\t<View />",
"\t\t</View>",
"\t)",
"};",
"",
"const styles = StyleSheet.create({",
"\tcontainer: {}",
"});"
],
"description": "React Native component"
}
}
スニペットの利用
Code > Preferences > User Snippets
tsxファイルのスニペットを作る場合typescriptreact
と入力
VS Codeではスニペットをファイル種別ごとにjsonファイルで管理します。
以下をコピペ
以下はReact Nativeのコンポーネントの一例です。お好みで変更して下さい。
{
"React Native Component": {
"prefix": "react-native-component",
"body": [
"import React from \"react\";",
"import { View, StyleSheet } from \"react-native\";",
"",
"type Props = {};",
"",
"export const ${TM_FILENAME_BASE}: React.FC<Props> = ({}) => {",
"\treturn (",
"\t\t<View style={styles.container}>",
"\t\t\t<View />",
"\t\t</View>",
"\t)",
"};",
"",
"const styles = StyleSheet.create({",
"\tcontainer: {}",
"});"
],
"description": "React Native component"
}
}
エディタでreact-native-component
と打ち込んでTabキー。
スニペットが挿入されます!
コンポーネント名はファイル名が自動的に反映されます。
Author And Source
この問題について(VS CodeのスニペットでReactのコンポーネント雛形を作る), 我々は、より多くの情報をここで見つけました https://qiita.com/takahi5/items/918dce8367c0f1edf676著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .