9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VS CodeのスニペットでReactのコンポーネント雛形を作る

Last updated at Posted at 2020-08-12

コンポーネントの雛形をVS Codeのスニペットに登録しておくと捗ります♪

スニペットの設定手順

  1. VS Codeの Code > Preferences > User Snippets

  2. tsxファイルのスニペットを作る場合typescriptreactと入力
    VS Codeではスニペットをファイル種別ごとにjsonファイルで管理します。
    スクリーンショット 2020-08-12 23.14.41.png

  3. 以下をコピペ
    以下は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キー。

スニペットが挿入されます!
コンポーネント名はファイル名が自動的に反映されます。

9ab7fc4ed4df7c0297cd34d53750df23.gif

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?