Skip to content

Instantly share code, notes, and snippets.

function updateState(dispatch) {
// helper functions
const dispatchError = e =>
dispatch(SET_STATUS({ status: 'error', message: e.message }));
dispatch(SET_STATUS({ status: 'submitting' }));
return fetch('https://example.com/api/a')
.then(() => {
dispatch(SET_STATUS({ status: 'processing' }));
function updateState(dispatch) {
const dispatchStatus = status => dispatch(SET_STATUS({ status }));
const dispatchError = e =>
dispatch(SET_STATUS({ status: 'error', message: e.message }));
dispatchStatus('submitting');
return fetch('https://example.com/api/a')
.then(() => {
dispatchStatus('processing');
const getResponseJson = async response => response.json();
function updateState(dispatch) {
const dispatchStatus = status => dispatch(SET_STATUS({ status }));
const dispatchError = e =>
dispatch(SET_STATUS({ status: 'error', message: e.message }));
const dispatchState = data => dispatch(SET_STATE({ data }));
dispatchStatus('submitting');
const getResponseJson = async response => response.json();
function updateState(dispatch) {
const dispatchStatus = status => dispatch(SET_STATUS({ status }));
const dispatchError = e =>
dispatch(SET_STATUS({ status: 'error', message: e.message }));
const dispatchState = data => dispatch(SET_STATE({ data }));
dispatchStatus('submitting');
const setStatus = (status, message) => SET_STATUS({ status, message });
const getResponseJson = async response => response.json();
const fetchUrl = url => () => fetch(url);
function updateState(dispatch) {
const dispatchStatus = status => () => dispatch(setStatus(status));
const dispatchError = ({ message }) => dispatch(setStatus('error', message));
const dispatchState = data => dispatch(SET_STATE({ data }));
dispatchStatus('submitting')();
const setStatus = (status, message) => SET_STATUS({ status, message });
const getResponseJson = async response => response.json();
const fetchUrl = url => () => fetch(url);
function updateState(dispatch) {
const dispatchStatus = status => () => dispatch(setStatus(status));
const dispatchError = ({ message }) => dispatch(setStatus('error', message));
const dispatchState = data => dispatch(SET_STATE({ data }));
return Promise.resolve()
for (let i = 0; i < array.length; i++) {
const el = array[i];
// do something here
}
Array.prototype.forEach(el => {
// do something here
});
for (const el of array) {
// do something here
}
.Modal {
/* fixed position will always show modal in the top left corner */
position: fixed;
top: 0;
left: 0;
/* z-index to show modal even if it is used before some other elements */
z-index: 5;
/* make modal fill whole window */
width: 100vw;
height: 100vh;