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"; | |
class List extends React.Component { | |
static propTypes = { | |
render: PropTypes.func.isRequired, | |
url: PropTypes.string.isRequired, | |
}; | |
state = { |
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
export default class CarsList extends React.Component { | |
state = { | |
cars: [], | |
isLoading: false, | |
}; | |
_fetch = async () => { | |
const res = await fetch("api/url"); | |
const json = await res.json(); | |
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
JSON.stringify({ | |
fileName: values.file.name, | |
type: values.file.type, | |
size: `${values.file.size} bytes` | |
}, null, 2); |
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
<input id="file" name="file" type="file" onChange={(event) => { | |
setFieldValue("file", event.currentTarget.files[0]); | |
}} /> |
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
Yup.object().shape({ | |
email: Yup.string().email('Invalid email address').required('Email is required!'), | |
username: Yup.string().required('This man needs a ${path}').when('email', (email, schema) => { | |
if (email === '[email protected]') { | |
return schema.label('papidipupi').min(10); | |
} | |
return schema.label('babidibiba'); | |
}).test('is-zigzagging', '${path} is not zigzagging', value => value === 'zigzagging'), | |
}); |
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
Yup.object().shape({ | |
email: Yup.string().email('Invalid email address').required('Email is required!'), | |
username: Yup.string().required('This man needs a ${path}').when('email', (email, schema) => { | |
if (email === '[email protected]') { | |
return schema.label('papidipupi').min(10); | |
} | |
return schema.label('babidibiba'); | |
}); |
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
Yup.object().shape({ | |
email: Yup.string().email('Invalid email address').required('Email is required!'), | |
username: Yup.string().required('This man needs a username').when('email', (email, schema) => { | |
if (email === '[email protected]') { return schema.min(10); } | |
return schema; | |
}), | |
}); |
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 } from 'formik'; | |
import Yup from 'yup'; | |
import VirtualizedSelect from 'react-virtualized-select'; | |
import 'react-select/dist/react-select.css'; | |
import 'react-virtualized/styles.css'; | |
import 'react-virtualized-select/styles.css'; | |
const imaginaryThings = [ |
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
// normal loop | |
for (var i = 0; i < array.length; i++) { | |
console.log(array[i]); | |
} | |
// optimized loop | |
for (var i = array.length - 1; i >= 0; i--) { | |
console.log(array[i]); | |
} |
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
// bad | |
function setSidebar() { | |
$('.sidebar').hide(); | |
// ... | |
$('.sidebar').css({ | |
'background-color': 'pink', | |
}); | |
} |