“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 的智能感知也会弹出建议列表,这有助于你发现和记住更多的前缀。

相关推荐
悟空瞎说5 分钟前
深度解析:Vue3 为何弃用 defineProperty,Proxy 到底强在哪里?
前端·javascript
leafyyuki6 分钟前
告别 Vuex 的繁琐!Pinia 如何以更优雅的方式重塑 Vue 状态管理
前端·javascript·vue.js
某人辛木22 分钟前
nodejs下载安装
开发语言·前端·javascript
zzginfo1 小时前
javascript 类定义常见注意事项
开发语言·前端·javascript
天下无贼!1 小时前
【功能实现】基于Vue3+TS实现大文件分片上传
开发语言·javascript·node.js·vue·html5
程序员小寒1 小时前
JavaScript设计模式(九):工厂模式实现与应用
开发语言·前端·javascript·设计模式
zhensherlock1 小时前
Protocol Launcher 系列:Agenda 优雅组织你的想法与日程
javascript·macos·ios·typescript·node.js·mac·ipad
清汤饺子1 小时前
Cursor + Claude Code 组合使用心得:我为什么不只用一个 AI 编程工具
前端·javascript·后端
代码煮茶2 小时前
Vue3 虚拟列表实战 | 解决长列表性能问题(十万条数据流畅渲染,附原理)
前端·javascript·vue.js
We་ct2 小时前
LeetCode 201. 数字范围按位与:位运算高效解题指南
开发语言·前端·javascript·算法·leetcode·typescript