Skip to content

Instantly share code, notes, and snippets.

View Arturszott's full-sized avatar

Artur Szott Arturszott

View GitHub Profile
@Arturszott
Arturszott / queue
Created November 5, 2022 09:18
Queue implementation
class QNode {
constructor(value) {
this.val = value;
this.next = null;
}
}
class MyQueue {
constructor() {
this.head = null;
@Arturszott
Arturszott / useResetableMutation.js
Created October 22, 2020 08:38
Apollo wrapper around useMutation to provide ability to reset
import { useState, useCallback, useMemo, useEffect } from 'react';
import { useMutation } from '@apollo/client';
const INITIAL_DATA_VALUE = undefined;
const useResetableMutation = (query, options) => {
const [customData, setCustomData] = useState(INITIAL_DATA_VALUE);
const customOptions = useMemo(() => {
const onCompleted = (responseData) => {
setCustomData(responseData);
options && options.onCompleted && options.onCompleted(responseData);
// thunk based action creator example, cannot be tested while calling mapDispatchToProps beside checking if dispatch was called
function saveScore (score) {
return (dispatch) => {
fetch('/scores', { method: 'POST', { score } })
.then(() => {
dispatch({ type: SAVE_SCORE_SUCCEEDED })
})
}
}