Skip to content

Instantly share code, notes, and snippets.

View fourstacks's full-sized avatar

John Wyles fourstacks

View GitHub Profile
@abhishekbhardwaj
abhishekbhardwaj / useStateIfMounted.ts
Last active February 15, 2021 14:36
useStateIfMounted: Use this instead of useState with Inertia.js if running into "Can't perform a React state update on an unmounted component". The error happens because the server-side redirect doesn't give your component enough time to clean up.
import { useEffect, useRef, useState } from "react";
export default function useStateIfMounted<T>(
initialState: T
): [T, (newState: T) => void] {
const isMounted = useRef(true);
const [state, setState] = useState(initialState);
useEffect(() => {
return () => {
@sebastiaanluca
sebastiaanluca / Controller.php
Last active March 7, 2023 23:51
A HasMany relation sync method implementation using macros
<?php
$business->locations()->sync([1, 42, 16, 8]);
@martinlindhe
martinlindhe / Alert.vue
Last active May 19, 2022 14:31
jasmine + karma for vue test
<style>
.Alert {
padding: 2em;
}
.Alert-Success {
border: 10px solid green;
}
.Alert-Error {
border: 10px solid red;
}