Skip to content

Instantly share code, notes, and snippets.

View emeraldsanto's full-sized avatar

Yanick Bélanger emeraldsanto

View GitHub Profile
@emeraldsanto
emeraldsanto / segment-proxy-react-native.ts
Last active March 17, 2021 01:23
Segment proxy (React Native)
import Segment from "analytics-react-native";
export const instance = new Segment(
'YOUR_WRITE_KEY',
{
proxy: {
scheme: 'http',
host: 'localhost',
port: 3000,
path: '/analytics/segment'
@emeraldsanto
emeraldsanto / segment-proxy-usage-react-native.ts
Last active March 17, 2021 01:22
Segment proxy usage (React Native)
import { instance } from './analytics';
// These events will be sent to your server instead of Segment's
instance.identify('some-user-id', { customProperty: 'custom value' });
instance.track('Custom Event', { userId: 'some-user-id' });
@emeraldsanto
emeraldsanto / segment-proxy-node.ts
Last active March 17, 2021 01:23
Segment proxy (Node)
import express from 'express';
import Segment from 'analytics-node';
const instance = new Segment('YOUR_WRITE_KEY');
const port = 3000;
const app = express();
// Enables JSON parsing middleware
app.use(express.json())
@emeraldsanto
emeraldsanto / use-reducer.tsx
Last active May 14, 2021 00:56
Small `useReducer` example
import { useReducer } from 'react';
/**
* There are much better ways to type this
* but this is not the focus of this gist.
*/
interface HTTPState<T> {
status: 'loading' | 'error' | 'success'
error?: string
data?: T
@emeraldsanto
emeraldsanto / react-navigation-linking-basic-example.tsx
Last active September 4, 2021 03:39
Achieving type safe deep linking in React Native with react-navigation #1
import { NavigationContainer } from '@react-navigation/native';
const linking = {
prefixes: ['https://mychat.com', 'mychat://'],
config: {
screens: {
Chat: 'feed/:sort',
Profile: 'user',
}
},
@emeraldsanto
emeraldsanto / react-navigation-linking-nested-example.tsx
Last active September 4, 2021 03:42
Achieving type safe deep linking in React Native with react-navigation #2
import { NavigationContainer } from '@react-navigation/native';
const config = {
screens: {
Home: {
initialRouteName: 'Feed',
screens: {
Profile: 'users/:id',
Feed: 'feed',
},
@emeraldsanto
emeraldsanto / react-navigation-old-navigator-example.tsx
Last active September 4, 2021 03:44
Achieving type safe deep linking in React Native with react-navigation #3
import { createStackNavigator } from '@react-navigation/stack';
import { Screen } from 'some-path/Screen';
import { ScreenOne } from 'some-path/ScreenOne';
import { ScreenTwo } from 'some-path/ScreenTwo';
import { ScreenThree } from 'some-path/ScreenThree';
const routeConfigMap = {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
@emeraldsanto
emeraldsanto / make-navigator-basic.tsx
Created September 4, 2021 03:45
Achieving type safe deep linking in React Native with react-navigation #4
export const SomeStackConfiguration = makeNavigator({
name: 'SomeStack',
type: 'stack',
screens: {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
},
linking: {
@emeraldsanto
emeraldsanto / make-navigator-custom.tsx
Last active September 4, 2021 03:48
Achieving type safe deep linking in React Native with react-navigation #5
const Tab = createBottomTabNavigator();
export const SomeTabConfiguration = makeNavigator({
name: 'SomeTab',
type: 'tab',
screens: {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
@emeraldsanto
emeraldsanto / make-navigator-implementation-types.ts
Created September 4, 2021 03:49
Achieving type safe deep linking in React Native with react-navigation #6
export enum Navigator {
One = 'NavigatorOne',
Two = 'NavigatorTwo',
Three = 'NavigatorThree',
}
export enum Screen {
One = 'ScreenOne',
Two = 'ScreenTwo',
Three = 'ScreenThree',