Skip to content

Instantly share code, notes, and snippets.

@hugo
hugo / saga.js
Created September 14, 2019 21:03
Saga extra arguments
// main.js
const api = new Api({ accessToken: '...', options: {} })
sagaMiddleware.run(rootSaga, api)
// saga.js
function* fetchUser(api, action) {
try {
const user = yield call(api.fetchUser, action.payload.userId);
yield put({ type: "USER_FETCH_SUCCEEDED", user: user });
@hugo
hugo / saga.js
Created September 14, 2019 21:13
Intermediate sagas
sagaMiddleware.run(rootSaga, someArg)
function* someSaga(someArg, action) {
// ...
}
function* rootSaga(someArg) {
yield takeEvery('SOME_ACTION', someSaga, someArg)
}
@hugo
hugo / withURQL.tsx
Created December 13, 2019 12:29
Wrap the Next `App` component in a `Provider` from `urql`
import {Provider, Client, createClient} from 'urql'
import NextApp, {AppContext} from 'next/app'
const isServer = typeof window === 'undefined'
type Props = {
client: Client
}
const withURQL = (App: typeof NextApp) =>