Skip to content

Instantly share code, notes, and snippets.

@hedgerh
hedgerh / README.md
Last active October 24, 2023 13:23
Sublime Text Snippet for a React component using ES6 class syntax.

ES6 Class style React Component Quick Generator Snippet

  1. Go to Tools > New Snippetin Sublime Text
  2. Paste the code from es6-create-class-component.sublime-snippet
  3. Feel free to change tabTriggerto a custom trigger, if you don't like rcc
  4. Save it anywhere in Packages/User.
  5. Inside of an empty js/jsx file, type the trigger (rcc by default), then press TAB or RETURN, and..

ES6 Class Style React Component Boilerplate

{
"kind": "stream_item",
"type": "playlist_repost",
"created_at": "2014/06/22 22:36:02 +0000",
"track": null,
"playlist": {
"kind": "playlist",
"id": 40585650,
"created_at": "2014/06/20 16:22:58 +0000",
"user_id": 315279,
'use statics';
export default {
FETCH_ME: 'FETCH_ME',
FETCH_LIKES: 'FETCH_LIKES',
FETCH_TRACKS: 'FETCH_TRACKS',
FETCH_USER: 'FETCH USER'
};
// prefer this
const ExamplePage = () => {
return (
<>
<div>
<h1>Card 1!</h1>
<h2>A simple card!</h2>
</div>
<div>
@hedgerh
hedgerh / PropValidation.tsx
Created April 29, 2019 23:44
Benefits of using Typescript with React #1: You get compile time prop validation and auto completion. This is especially helpful when working with a 3rd party UI library that you aren't 100% familiar with yet.
import React from 'react';
interface IImage {
alt: string;
src: string;
}
interface IGalleryProps {
images: IImage[]
}
import { call, put, takeLatest } from 'redux-saga/effects'
import client from '../httpClient'
const createAction = (type) => (payload) => ({
type,
payload,
})
const http = {
login: (credentials) => client.post('/login', credentials),
import { call, put, takeLatest } from 'redux-saga/effects'
import { createStandardAction, ActionType, getType } from 'typesafe-actions'
import client from '../httpClient'
interface ILogin {
email: string;
password: string;
}
interface IUser {
const foo = 'hello'
@hedgerh
hedgerh / index.tsx
Last active March 23, 2019 00:38 — forked from phd20/index.tsx
Working version of container that returns array of objects
import { connect } from "react-redux";
import Dashboard from "./dashboard";
import { ApplicationState } from "../../store";
const mapStateToProps = (state: ApplicationState) => {
const sessions = sessionsArraySelector(state)
console.log(sessions)
return {
user: state.oidc.user,
sessions: Object.values(sessions),
@hedgerh
hedgerh / http.js
Last active January 22, 2019 17:51
Example http module with Axios
import axios from 'axios'
export const http = axios.create({
baseUrl: 'https://localhost:3000',
headers: {
//...
},
})
http.interceptors.response.use(response => response.data, err => throw new Error(err))