Skip to content

Instantly share code, notes, and snippets.

View export-mike's full-sized avatar
📱
GO, React, React Native, Node.js in Syndey Australia

Mike James export-mike

📱
GO, React, React Native, Node.js in Syndey Australia
View GitHub Profile
@export-mike
export-mike / index.js
Last active November 8, 2017 04:44
react-plural
import React from 'react';
export default props => {
const messageBuilt = plural(props);
return <span>{messageBuilt}</span>;
};
export const plural = ({ message, ...rest }) => {
const messageBuilt = Object.keys(rest).reduce((messageTemplate, key) => {
if (!Array.isArray(rest[key])) {
@export-mike
export-mike / Request.js
Last active November 8, 2017 01:26
ReactRequestHigherOrderComponent - with custom Loading component, leverages async await
import React from 'react';
import Api from '../Api';
import Loading from '../components/Loading';
import Title from '../components/Title';
const withRequest = ({ fetch, prop, defaultState, LoadingComponent }) => Component => class WithRequest extends React.Component {
state = {
[prop]: defaultState,
loading: false,
error: false
@export-mike
export-mike / ReactProvderFactory.js
Last active November 8, 2017 00:53
ReactProviderFactory.js - create simple providers with accompanying higher order 'with' components to access context.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default (propName, propType, contextProp) => {
return {
Provider: createProvider(propName, propType, contextProp),
Hoc: createHigherOrderComponent(propName, propType, contextProp)
}
};
@export-mike
export-mike / ReactProvderFactory.js
Created November 8, 2017 00:43
ReactProviderFactory.js - create simple providers with accompanying higher order 'with' components to access context.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default (propName, propType, contextProp) => {
return {
Provider: createProvider(propName, propType, contextProp),
Hoc: createHigherOrderComponent(propName, propType, contextProp)
}
};
@export-mike
export-mike / dropDataGraphCool.js
Created July 19, 2017 13:07
A utility Script for cleaning out tables in graphcool
require('dotenv').config();
const { GraphQLClient } = require('graphql-request');
const client = new GraphQLClient(process.env.ENDPOINT, { headers: {
'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`
}});
const query = T => `
query Get${T}s {
all${T}s {
id
@export-mike
export-mike / lighthouse.io.js
Last active April 2, 2017 05:09
lighthouse.io code test
import { compose, pure } from 'recompose'
import { Component } from 'react'
import Radium from 'radium' // great styling library! I
// I'd also consider styled-components now its really neat and much more react style
/** for example purposes we've got some other components that are not defined,
I've added a spinner which would render a CSS animation in place of the table.
I've got a Button comonent which renders the styled buttons we have in the screenshot, they could have clicks attached.
@export-mike
export-mike / .bash
Created April 2, 2017 05:06
react-init
yarn add webpack@^2 babel-core babel-loader babel-preset-react babel-preset-stage-2 prettier eslint@^3 react@^15 react-dom@^15enzyme nightmare jest eslint-config-prettier prettier-eslint-cli styled-components --dev && git init && git ignore-io node && echo '{"extends":"prettier"}' > .eslintrc && echo '{"presets": ["stage-2", "react"]}' > .babelrc
@export-mike
export-mike / redux.js
Created March 14, 2017 04:51
How Does Redux Work?
import compose from 'recompose/compose';
import EventEmitter from 'event-emitter';
const combineReducers = reducersMap => {
const arrayOfReducers = Object.keys(reducersMap)
.reduce((acc, r) => [...acc, reducersMap[r]], []);
return compose.apply(null, arrayOfReducers);
}
const dispatch = reducers => action => reducers(action);
@export-mike
export-mike / createReducer.js
Created February 27, 2017 00:48
a helper function to transform a map into a nice clean reducer with no switch statements.
/**
* Utility method to create a reducer from a map,
* with initial state
* @param initialState
* @param reducerMap
* @returns {Function}
*/
export default function createReducer(initialState, reducerMap) {
return (state = initialState, action) => {
@export-mike
export-mike / build
Created June 29, 2016 13:59
react-docgen build file for typical react redux apps, you can then call this from you CI build or pre commit or do it manually whatever.
#!/usr/bin/env bash
rm -rf views containers components
mkdir views && cd views
react-docgen ../../src/views/ --resolver findAllComponentDefinitions --ignore test | ../buildDocs && cd ..
mkdir containers && cd containers
react-docgen ../../src/containers/ --resolver findAllComponentDefinitions --ignore test | ../buildDocs && cd ..
mkdir components && cd components
react-docgen ../../src/components/ --resolver findAllComponentDefinitions --ignore test | ../buildDocs && cd ..