This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import debounce from 'utils/debounce'; | |
class EmailInput extends React.Component { | |
checkEmail = value => { | |
// only check if the field passes Yup email validation first | |
if ( | |
!this.props.form.errors[this.props.name].includes( | |
'invalid' /* or whatever your error message is*/ | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def nCr(num, kVal): | |
"""Returns a nCr combination | |
Args: | |
num (int): The numerator. | |
kVal (str): The size of the set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { css as EmotionCSS } from 'react-emotion'; | |
import { jsxstyleFactory } from './jsxstyleFactory'; | |
const cx = (css, styles, className) => | |
EmotionCSS([{ ...css, ...styles }, className]); | |
const jsxstyle = jsxstyleFactory(cx); | |
export const Box = jsxstyle.Box; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { css as Style } from 'glamor'; | |
const View = ({ | |
component = 'div', | |
props, | |
css, | |
className, | |
children, | |
...rest, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prefetch(getKey, getValue, getInitialValue, propName) { | |
const inFlight = new Set(); | |
const cache = new Map(); | |
return ChildComponent => { | |
return class extends React.Component { | |
state = {value: getInitialValue(this.props)}; | |
componentWillReceiveProps(nextProps) { | |
const key = getKey(nextProps); | |
if (cache.has(key)) { | |
// Use cached value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import PropTypes from 'prop-types' | |
import debounce from 'lodash.debounce' // or whatevs | |
import isEqual from 'lodash.isEqual' | |
class AutoSave extends React.Component { | |
static contextTypes = { | |
formik: PropTypes.object | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { Formik, Field, Form } from 'formik' | |
const MyInput = ({ field, form, ...rest }) => | |
<div> | |
<input {...field} {...rest} /> | |
{form.errors[field.name] | |
&& form.touched[field.name] | |
&& <div>{form.errors[field.name]}</div>} | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { Formik, Field, Form } from 'formik' | |
const App = () => | |
<div> | |
<h1>My Login Form</h1> | |
<p>This can be anywhere in your application</p> | |
<Formik | |
initialValues={{ email: '', password: '', favorite: 'Kirk' }} | |
validate={values => { /* omitted for brevity */ }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Basic = () => | |
<div> | |
<h1>My Form</h1> | |
<p>This can be anywhere in your application</p> | |
<Formik | |
initialValues={{ email: '', password: '' }} | |
validate={values => { /* omitted for brevity */ }} | |
onSubmit={values => { /* omitted for brevity */ }} | |
render={({ values, errors, touched, handleChange, handleSubmit, isSubmitting }) => | |
<form onSubmit={handleSubmit}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
class ReducerComponent<Props, State> extends React.Component<Props, State> { | |
constructor(props: Props) { | |
super(props); | |
} | |
reducer = (state: State, action: string) => { | |
// this should be | |
return state; |