Giter Club home page Giter Club logo

vscode-react's Introduction

Reactjs

VS Code Reactjs snippets


Version Installs Ratings

This extension contains code snippets for Reactjs and is based on the awesome babel-sublime-snippets package.

Installation

In order to install an extension you need to launch the Command Palette (Ctrl + Shift + P or Cmd + Shift + P) and type Extensions. There you have either the option to show the already installed snippets or install new ones.

Supported languages (file extensions)

  • JavaScript (.js)
  • TypeScript (.ts)
  • JavaScript React (.jsx)
  • TypeScript React (.tsx)

Breaking change in version 2.0.0

Removed support for jsx language as it was giving errors in developer tools #39

Breaking change in version 1.0.0

Up until verion 1.0.0 all the JavaScript snippets where part of the extension. In order to avoid duplication the snippets are now included only to this extension and if you want to use them you have to install it explicitly.

Usage

When installing the extension React development could be really fun create react component

As VS Code from version 0.10.10 supports React components syntax inside js files the snippets are available for JavaScript language as well. In the following example you can see the usage of a React stateless component with prop types snippets inside a js and not jsx file. create react stateless component

Snippets

Below is a list of all available snippets and the triggers of each one. The means the TAB key.

Trigger Content
rcc→ class component skeleton
rrc→ class component skeleton with react-redux connect
rrdc→ class component skeleton with react-redux connect and dispatch
rccp→ class component skeleton with prop types after the class
rcjc→ class component skeleton without import and default export lines
rcfc→ class component skeleton that contains all the lifecycle methods
rwwd→ class component without import statements
rpc→ class pure component skeleton with prop types after the class
rsc→ stateless component skeleton
rscp→ stateless component with prop types skeleton
rscm→ memoize stateless component skeleton
rscpm→ memoize stateless component with prop types skeleton
rsf→ stateless named function skeleton
rsfp→ stateless named function with prop types skeleton
rsi→ stateless component with prop types and implicit return
fcc→ class component with flow types skeleton
fsf→ stateless named function skeleton with flow types skeleton
fsc→ stateless component with flow types skeleton
rpt→ empty propTypes declaration
rdp→ empty defaultProps declaration
con→ class default constructor with props
conc→ class default constructor with props and context
est→ empty state object
cwm→ componentWillMount method
cdm→ componentDidMount method
cwr→ componentWillReceiveProps method
scu→ shouldComponentUpdate method
cwup→ componentWillUpdate method
cdup→ componentDidUpdate method
cwun→ componentWillUnmount method
gsbu→ getSnapshotBeforeUpdate method
gdsfp→ static getDerivedStateFromProps method
cdc→ componentDidCatch method
ren→ render method
sst→ this.setState with object as parameter
ssf→ this.setState with function as parameter
props→ this.props
state→ this.state
bnd→ binds the this of method inside the constructor
disp→ MapDispatchToProps redux function

The following table lists all the snippets that can be used for prop types. Every snippet regarding prop types begins with pt so it's easy to group it all together and explore all the available options. On top of that each prop type snippets has one equivalent when we need to declare that this property is also required.

For example pta creates the PropTypes.array and ptar creates the PropTypes.array.isRequired

Trigger Content
pta→ PropTypes.array,
ptar→ PropTypes.array.isRequired,
ptb→ PropTypes.bool,
ptbr→ PropTypes.bool.isRequired,
ptf→ PropTypes.func,
ptfr→ PropTypes.func.isRequired,
ptn→ PropTypes.number,
ptnr→ PropTypes.number.isRequired,
pto→ PropTypes.object,
ptor→ PropTypes.object.isRequired,
pts→ PropTypes.string,
ptsr→ PropTypes.string.isRequired,
ptsm→ PropTypes.symbol,
ptsmr→ PropTypes.symbol.isRequired,
ptan→ PropTypes.any,
ptanr→ PropTypes.any.isRequired,
ptnd→ PropTypes.node,
ptndr→ PropTypes.node.isRequired,
ptel→ PropTypes.element,
ptelr→ PropTypes.element.isRequired,
pti→ PropTypes.instanceOf(ClassName),
ptir→ PropTypes.instanceOf(ClassName).isRequired,
pte→ PropTypes.oneOf(['News', 'Photos']),
pter→ PropTypes.oneOf(['News', 'Photos']).isRequired,
ptet→ PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
ptetr→ PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
ptao→ PropTypes.arrayOf(PropTypes.number),
ptaor→ PropTypes.arrayOf(PropTypes.number).isRequired,
ptoo→ PropTypes.objectOf(PropTypes.number),
ptoor→ PropTypes.objectOf(PropTypes.number).isRequired,
ptoos→ PropTypes.objectOf(PropTypes.shape()),
ptoosr→ PropTypes.objectOf(PropTypes.shape()).isRequired,
ptsh→ PropTypes.shape({color: PropTypes.string, fontSize: PropTypes.number}),
ptshr→ PropTypes.shape({color: PropTypes.string, fontSize: PropTypes.number}).isRequired,

vscode-react's People

Contributors

bpugh avatar cezarneaga avatar darko avatar hojondo avatar jamesalias avatar jankalfus avatar juandelacruz23 avatar kant avatar kylemh avatar matt-jolt avatar mohithg avatar morenomdz avatar poulet42 avatar rusinovanton avatar sdustin avatar selrond avatar timcluyts avatar vincentbel avatar vladsholokhov avatar xabikos avatar ywpark1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vscode-react's Issues

How can I change the snippets?

Great tool!

I prefer a different snippet for rcc than the one configured. How can I change it?

My preferred snippet:

import * as React from "react";

export class MyComp extends React.Component {
  render() {
    return (
      <React.Fragment>
        <p>abc</p>
      </React.Fragment>
    );
  }
}

Support propTypes defined as static class property

Hi @xabikos.

thanks a lot for this project! I've using React Snippets about one week and It saved me a lot of time already. There is one thing - I'm already using static class properties but can't make a PR because my approach don't follow the official EcmaScript standard yet. And there is no way, how to customize your snippets.

before

class Example extends Component {        
        render() {
            return (
                <div>
                    
                </div>
            );
    }
}

Example.propTypes = {

};

export default Example;

I decided to create this patch script that can be used directly from the terminal, so I can share this method with you all here.

after the patch

class Example extends Component {
        static propTypes = {

        };
        
        render() {
            return (
                <div>
                    
                </div>
            );
    }
}

export default Example;

You can use this method for patching any of current snippets or to add some new ones...

Some snippets don't work

Hi. Just have check with the latest version of VSCode (1.8.0) and the latest version of the plugin (1.2.0), the following snippets don't work:

props→	this.props
state→	this.state

Redux Connect

Hi, I downloaded the extension v1.4.0 and the Redux Connect (rrc) snippet isn't there?

Doesn't work

Issue Type: Bug

All extensions doesn't work... specially "Reactjs code snippets"

Extension version: 2.4.0
VS Code version: Code 1.40.0 (86405ea23e3937316009fc27c9361deee66ffbf5, 2019-11-06T17:02:13.381Z)
OS version: Windows_NT x64 10.0.17134

System Info
Item Value
CPUs Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz (4 x 2195)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off
surface_control: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 3.91GB (0.55GB free)
Process Argv
Screen Reader no
VM 67%

Add generic PropTypes.objectOf(PropTypes.shape).isRequired

Not an issue, more of a possible request...
One PropType we use often, but is not included in this extension, is the generic : PropTypes.objectOf(PropTypes.shape).isRequired

Not sure if it was a conscious decision or if there is some other reason for not including it.

Error on Dev Tools

Every time I open the VSCode, I got this error on VS Code Dev Tools:

[{USER_PATH}/.vscode/extensions/xabikos.ReactSnippets-1.7.0]: Unknown language in `contributes.ReactSnippets.language`. Provided value: jsx

I already tryied uninstalling the extension, and installing it again, but right after installing it, shows up again.

rcc code style guide & code format bug!

good code format

import React, {Component} from 'react';

class componentName extends Component {
    render() {
        return(
            <div>
                {/* comments */}
            </div>
        );
    }
}

export default componentName;

not too good

import React, { Component } from 'react'

class componentName extends Component {
    render () {
        return (
            <div>
                
            </div>
        )
    }
}

export default componentName

'export default component' syntax should be removed from 'rcc' snippet

A normal React component is not always be the one which should be exported, so rcc snippet should only create a class without export default component syntax and instead replace it with rcced or something else.

By the way it would be better if 'con' snippet creates constructor(props, context) rather than constructor(props).

Thank you for founding this convenient extension, I believe both of these changes are not difficult to implement, right?

Respect eslint config when inserting snippets

This would be great to format snippets according to existing eslint rules of the project.

Because for now, when I insert a snippet I have lots of eslint warnings:

index1 js - first-agenda 2016-12-15 11-00-14

So I have to save the file for eslint plugin to fix all of them:

index1 js - first-agenda 2016-12-15 11-00-36

This happens because I have "eslint.autoFixOnSave": true setting enabled.

If it happened automatically (before inserting the snippet into the editor), it would be awesome.

Can we add it, what do you think?

Release next version?

There are currently 6 commits in master that haven't been released. Can we get a new version published 🙏

Bug Report

Type: Bug

Extension Bisect is done and has identified xabikos.reactsnippets as the extension causing the problem.

Extension version: 2.4.0
VS Code version: Code 1.72.2 (d045a5eda657f4d7b676dedbfa7aab8207f8a075, 2022-10-12T22:16:30.254Z)
OS version: Darwin x64 20.6.0
Modes:
Sandboxed: No

System Info
Item Value
CPUs Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz (8 x 2200)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 8, 6, 14
Memory (System) 16.00GB (0.62GB free)
Process Argv --crash-reporter-id d1581a72-00ea-464e-a077-20ba022f3809
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vscaac:30438847
vsclangdf:30486550
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
2144e591:30553903
vsccc:30566497
pyindex848cf:30577861
nodejswelcome1:30587005
fc301958:30573243

'met' not working

Hey, just tried using the code snippets but when typing "met" as per your gif it doesn't give any options.

Snippet rpt does not work

It seems rpt snippet does not work for me. Wondering whether it is an issue of my configuration or clash of some other existing configurations.

To reproduce:
image

Anyone else facing this issue?

Other snippet works just fine.

Versions:

  • VSCode v1.21.1
  • Snippets plugin v2.0.0

Snippet not working on [dot]JSX file.

I just install this snippet on latest visual studio code, I'm on mac. This snippet works on file with .js extension but not appear on .jsx files.

rdp is missing the default Name

The snippet rpt generates the empty propTypes and it pre-populates the component name (I'm guessing from the file name but not certain) but the rdp does not copy this behavior, it neglects the name.

rpt ->
MyComponent.propTypes = {
  
};

rdp ->
.defaultProps = {
  
};

update template

hello, I want to edit rcc command generate template

because I not like this:

import {Component} from 'react'

I want to this:

import { Component } from react

haha~ how to edit it I want to know? Thanks ^0^

How to work with prop-types package?

When I enter 'rscp', I want to generate this:

import React from 'react';
import PropTypes from 'prop-types';

const ComponentName = props => {
  return (
    <div>

    </div>
  );
};

ComponentName.propTypes = {

};

export default ComponentName;

But, it will generate this code:

import React, { PropTypes } from 'react';

const ComponentName = props => {
  return (
    <div>

    </div>
  );
};

ComponentName.propTypes = {

};

export default ComponentName;

How to work with prop-types package?

Add state to rcc

With react 16, state doesn't need to be created in the constructor. Therefore I would suggest upon creation of stateful components to be included

export default class componentName extends Component {
  state  = {}
  render() {
    return (
      <div>
        
      </div>
    )
  }
}

Two proptypes missing

Hi,

frist of all: very nice extension!
refereing to this List
I have gathered all the PropTypes:

PropTypes.array,
PropTypes.bool,
PropTypes.func,
PropTypes.number,
PropTypes.object,
PropTypes.string,
PropTypes.node,
PropTypes.element,

PropTypes.symbol,
PropTypes.any

The last two are missing in then PropType-snippets. Did you forgot them or did you leave them out on purpose? If it is the former could you maybe add them?

It's just a question

Why does the reactStateless (rsc) do export default but the flowStatelessComponent (fsc) just do export?

ssf snippet invalid

this.setState($1:(state, props) => $0});\n; should be this.setState((state, props) => { return { $0 } });

Snippet auto suggestions not showing after first character

Snippet suggestions from Reactjs code snippets extension are showing intermittently.

When they DO show:

  1. When I escape auto suggestions and press Ctrl + SPACE
  2. When I type a single character of an abbreviation
  3. When I type the first character, then escape suggestions, then navigate away to another virtual desktop, navigate back, and type the second character of a snippet abbreviation.
  4. When I create a new file and type the whole/partial abbreviation without backspacing at all.

When they DON'T show:

  1. When I type 2 or more characters of an abbreviation.
  2. When I backspace in the middle of an abbreviation (intermittent).

I have tried disabling all extensions and enabling only Reactjs code snippets and still observed the same behavior.

I enabled verbose logging but didn't see anything relevant.

Here's a video but i'm not sure how helpful it will be.

Screen.Recording.2023-02-06.at.2.25.16.PM.mp4

PropTypes now separate package when using snippet "rscp"

Line 1: React.PropTypes is deprecated since React 15.5.0, use the npm module prop-types instead react/no-deprecated
Line 1: 'PropTypes' is defined but never used no-unused-vars

When using snippet "rscp"

Maybe have import PropTypes from "prop-types" ?

Whats the name of plugin

Cannot find the name of plugin which i should use while executing command ext install.

I tried using ext install vscode-react but no result was returned. Currently using code v1.0.0

Use array on body for better readability

Instead of using \n on body to break lines like this:

"classConstructorContext": {
  "prefix": "conc",
  "body": "constructor(props, context) {\n\tsuper(props, context);\n\t$0\n}\n",
  "description": "Adds a default constructor for the class that contains props and context as arguments"
},

use an array for better readability:

"classConstructorContext": {
  "prefix": "conc",
  "body": [
    "constructor(props, context) {",
    "\tsuper(props, context);",
    "\t$0",
    "}"
  ],
  "description": "Adds a default constructor for the class that contains props and context as arguments"
},

That way others can contribute easily or use your snippets as a starting point for their owns.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.