Skip to content

Instantly share code, notes, and snippets.

@flatlinediver
flatlinediver / mailgun.js
Last active March 10, 2021 13:37
Form handler using Mailgun and Netlify Functions
const { MAILGUN_API_KEY: apiKey, DOMAIN: domain, RECEIVER_MAIL: receiver_mail } = process.env
const mailgun = require('mailgun-js')({ apiKey, domain })
exports.handler = function(event, context, callback) {
if(event.httpMethod!='POST' || !event.body){
return callback(new Error('An error occurred!'))
}
const data = JSON.parse(event.body)
@flatlinediver
flatlinediver / input.js
Created March 1, 2019 00:58
Handling input using React Hooks
import React, {useState} from 'react'
export const Input = () => {
const [ inputValue, setinputValue ] = useState()
const handleChange = ({ target: {value} }) => setinputValue(value)
return(
<input name='name' value={ inputValue } onChange={ handleChange }/>
)
}
@flatlinediver
flatlinediver / transitionMotion.js
Created March 1, 2019 01:00
React transitions using React Motion
import React from 'react'
import { Route, Switch, withRouter } from 'react-router-dom'
import { Transition,TransitionGroup } from 'react-transition-group'
import { StaggeredMotion, spring } from 'react-motion'
import {timeout} from '../constants'
export const Component = memo(({param, status}) => {
const options = {stiffness: 470, damping: 25}
const defaultStyles = [{x: -50}, {x: -50}]
return(
@flatlinediver
flatlinediver / styled-react-select.js
Last active March 30, 2020 20:40
react-select when using styled components
import React, {useContext, useState} from 'react'
import { ThemeContext } from 'styled-components';
import Select from 'react-select'
const styles = {
control: (provided, { selectProps: { theme, anotherProp } }) => ({
...provided,
background: anotherProp,
boxShadow: theme.shadow(),
border: 'none',
@flatlinediver
flatlinediver / StyledThemeWithUnits.ts
Last active February 8, 2021 02:06
Constructing Styled Theme with inferred units
type ItemsWithUnit<T> = T & { [P in keyof T & string as `_${P}`]: T[P] };
const withUnit = <T>(items: T, unit = 'px'): ItemsWithUnit<T> => {
let newObj = {};
Object.keys(items).forEach((key) => {
const originalElement = items[key as keyof T];
if (typeof originalElement !== 'number') {
newObj = {
...newObj,
[key]: originalElement,