Skip to content

Instantly share code, notes, and snippets.

@titoasty
titoasty / createSharedHook.ts
Last active July 6, 2020 08:00
create a simple shared hook between components
import { useReducer, useEffect } from 'react';
const useForceUpdate = () => useReducer((state) => !state, false)[1];
function createSharedState(reducer, initialState) {
const subscribers: any[] = [];
let state = initialState;
const dispatch = (action) => {
state = reducer(state, action);
@titoasty
titoasty / log_device.js
Created July 26, 2019 13:49
let's colorize react-native log-ios / log-android
const spawn = require('child_process').spawn;
const chalk = require('chalk');
const endOfLine = require('os').EOL;
const deviceType = process.argv[2];
const cmd = spawn('react-native', [deviceType == 'ios' ? 'log-ios' : 'log-android']);
function log(msg) {
console.log(msg);
}