Skip to content

Instantly share code, notes, and snippets.

View scorsi's full-sized avatar
😬
What if... hugh.. whatever

Sylvain Corsini scorsi

😬
What if... hugh.. whatever
  • Asobo Studio
  • France, Lille
  • 03:39 (UTC +02:00)
View GitHub Profile
@scorsi
scorsi / useIsMounted.js
Created February 27, 2020 15:07
A hook useful to know if the current component is still mounted
import { useEffect, useRef } from 'react';
export default () => {
const isMounted = useRef(null);
useEffect(() => {
isMounted.current = true;
return () => { isMounted.current = false; };
}, []);
@scorsi
scorsi / fetch.js
Created February 27, 2020 15:18
A Fetch hook with super-powers, lightweight but very performant
// eslint-disable-next-line import/no-mutable-exports,prefer-const
export let baseUrl = process.env.REACT_APP_API_DOMAIN;
export const constructUrl = (path, queryParams = null) => {
const _url = new URL(baseUrl);
_url.pathname = path;
if (queryParams) _url.search = new URLSearchParams(queryParams).toString();
return _url.toString();
};
@scorsi
scorsi / useWindowDimensions.tsx
Last active April 30, 2020 14:47
Get window width and match
import {useEffect, useState} from 'react';
const getWindowDimensions = () => {
const {innerWidth: width, innerHeight: height} = window;
return {
width,
height
};
};
defmodule Torch.Templates do
@moduledoc """
Module allowing to automatically manage templates depending of the given mix task
"""
@template_path "priv/templates"
def inject_templates(mix_task, options) do
out_directory = Keyword.get(options, :out_directory, "#{@template_path}/#{mix_task}")