“ES7+ React/Redux/React-Native snippets“常用快捷前缀

请注意,这是一个常用的列表,不是扩展提供的所有前缀。最完整和最新的列表请参考扩展的官方文档或在 VS Code 中查看扩展的详情页面。

React (通常用于 .js, .jsx, .ts, .tsx):

  • rfce: React Functional Component with Export Default
  • rafce: React Arrow Function Component with Export Default
  • rce: React Class Component with Export Default
  • rcc: React Class Component
  • rpc: React Pure Class Component
  • rconst: Adds constructor and super (in a class)
  • rprops: Adds defaultProps (in a class or functional component)
  • rpropst: Adds propTypes (in a class or functional component)
  • rstate: Adds state object (in a class)
  • rcontext: React Context boilerplate

React Hooks (通常用于 .js, .jsx, .ts, .tsx):

  • usf: useState hook template (e.g., const [name, setName] = useState(initialValue);)
  • useEffect: useEffect hook template
  • useRef: useRef hook template
  • useMemo: useMemo hook template
  • useCallback: useCallback hook template
  • useContext: useContext hook template
  • useReducer: useReducer hook template
  • useImperativeHandle: useImperativeHandle hook template
  • useLayoutEffect: useLayoutEffect hook template
  • useDebugValue: useDebugValue hook template

React Native (通常用于 .js, .jsx, .ts, .tsx):

  • rnfe: React Native Functional Component with Export Default
  • rnfce: React Native Functional Component with Export
  • rnsc: React Native Stylesheet Create (StyleSheet.create({}))
  • rnssc: React Native Stylesheet Create with styles constant (const styles = StyleSheet.create({}))
  • rncss: React Native Stylesheet Create shorthand (just styles)

Lifecycle Methods (Class Components):

  • cdm: componentDidMount
  • cdup: componentDidUpdate
  • cwunmount: componentWillUnmount
  • cdc: componentDidCatch
  • cgsb: getSnapshotBeforeUpdate
  • cserender: shouldComponentUpdate

Redux:

  • redux-reducer: Basic Redux reducer structure
  • redux-action: Basic Redux action creator structure

Other / Utilities:

  • imr: import React from 'react'
  • imrc: import React, { Component } from 'react'
  • imrpc: import React, { PureComponent } from 'react'
  • imrce: import React, { Component } from 'react' + Export Default (for class)
  • imp: Generic Import (import ... from ...)
  • impt: Generic Import Type (import type ... from ...)
  • impc: Generic Import CSS (import './style.css')
  • log: console.log()
  • clg: console.log() (similar to log)
  • clo: console.log(object)

再次提醒,这个列表涵盖了大多数你可能日常使用的片段。当你安装了扩展后,在编辑器中输入前缀时,VS Code 的智能感知也会弹出建议列表,这有助于你发现和记住更多的前缀。

相关推荐
pas1369 分钟前
27-mini-vue provide-inject
前端·javascript·vue.js
h_jQuery17 分钟前
vue项目中使用canvas实现手写文字(批注)功能
开发语言·前端·javascript
winfredzhang20 分钟前
[全栈实战] 从零打造一个“沉浸式”私人云端阅读器 (Node.js + EPUB.js)
javascript·css·node.js·html·extjs·epub阅读器
duanyuehuan25 分钟前
|| ?. ?? ??= 4种操作符
前端·javascript·vue.js
坚果派·白晓明28 分钟前
Windows 11 OpenHarmony版React Native开发环境搭建完整指南
react native·开源鸿蒙·rnoh
特严赤傲34 分钟前
H5 页面在微信浏览器里调用微信支付 demo
javascript·微信·jsapi
qq_401967381 小时前
element-plus table组件 封装列隐藏功能,并非 v-if 或 v-for,通过tableRef 与样式控制
javascript·vue.js·elementui
徐同保1 小时前
react组件内添加一个全局点击时间,点击函数能区分是否是某个特定的id的dom触发的
前端·javascript·react.js
前端 贾公子6 小时前
v-if 与 v-for 的优先级对比
开发语言·前端·javascript
小二·10 小时前
Pinia 完全指南:用 TypeScript 构建可维护、可测试、可持久化的 Vue 3 状态管理
javascript·vue.js·typescript