Skip to content

Instantly share code, notes, and snippets.

@misterfresh
misterfresh / UserView.js
Last active February 26, 2018 15:15
Get the active user info directly from the global state instead of receiving it as a prop from the parent component
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { getUser } from 'user/selectors'
class UserView extends PureComponent {
render() {
let { user } = this.props
return (
<div>
// don't make a specific component just to add a style, don't do
let BlueButton = ({children}) => <button style={{color: 'blue'}}>{children}</button>
let MyPage = () => <div>
<BlueButton>Add item</BlueButton>
</div>
// in this case just use the default html button tag, just do
let MyPage = () => <div>
<button style={{color: 'blue'}}>Add item</button>
</div>
@misterfresh
misterfresh / TitleInSlotExample.js
Last active February 26, 2018 14:06
Use slots instead of props
// don't do
let AddItemToCartButton = ({icon, title}) => <button>{!!icon && <i className={'fa fa-' + icon}/>}{title}</button>
// this forces you to add a prop
<AddItemToCartButton title=”Add item to cart” />
// and with icon
<AddItemToCartButton title=”Add item to cart” icon="plus"/>
//do
let AddItemToCartButton = ({children}) => <button>{children}</button>
//this is more explicit
@misterfresh
misterfresh / Menu.js
Created February 26, 2018 13:50
Menu as a single component
// if menu items are static
let Menu = () => <ul>
<li><a href="/home">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
export default Menu
@misterfresh
misterfresh / MenuGroup.js
Created February 26, 2018 13:46
Menu with separate Components
import MenuItem from './MenuItem'
let MenuGroup = ({menuLinks}) => <ul>
{menuLinks.map( menuLink => <MenuItem menuLink={menuLink}/>)}
</ul>
export default MenuGroup
@misterfresh
misterfresh / Fill.js
Created October 3, 2016 20:27
React Slider With Range
'use strict'
import React, { PropTypes, Component } from 'react'
let Fill = ({
start, end,
getPositionFromValue
}) =>
<div
className='rangeslider__fill'
style={{
left: (getPositionFromValue(start) + 10 )+ 'px',
@misterfresh
misterfresh / sendMail.js
Last active March 29, 2022 07:26
Forward emails to SendGrid and log IP of senders
// Publish it as a Google App Script Web App to forward email from the contact form to your email using SendGrid
// This is intended for use with https://github.com/misterfresh/react-drive-cms
var sendGridApiKey =
'YOUR-SENDGRID-API-KEY'
var sendGridVerifiedSenderEmail = 'YOUR-SENDGRID-VERIFIED-SENDER-EMAIL'
var sendGridVerifiedSenderName = 'YOUR-SENDGRID-VERIFIED-SENDER-NAME'
var contactEmail = 'YOUR-CONTACT-EMAIL'
var contactName = 'YOUR-CONTACT-NAME'
var visitorsSpreadsheetName = 'Visitors'
@misterfresh
misterfresh / prepareSheets.js
Last active June 3, 2020 13:05
Add an Update button to the Dashboard for React Drive CMS
// This script is intended for use with https://github.com/misterfresh/react-drive-cms
// Add it as a bound script to the Dashboard Sheet file
function onOpen() {
var dashboard = SpreadsheetApp.getActiveSpreadsheet();
var updateDashboard = [{name: "Update Dashboard", functionName: "prepareSheets"}];
dashboard.addMenu("Update", updateDashboard);
}
function prepareSheets() {
var Preparator = {