Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Sébastien Lorber slorber

🏠
Working from home
Block or report user

Report or block slorber

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:dcfb9c0fed8ebebb8ffe14230aca2485
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import useConstant from 'use-constant';
import produce from 'immer';
import { useIsMountedFn } from './useIsMounted';
View ElementContainer.js
import React from 'react';
const generateHolderKey = (() => {
let counter = 0;
return () => {
counter += 1;
return `holder_${counter}`;
};
})();
View setupAppOverTheAirUpdates.js
const setupAppOverTheAirUpdates = () => {
const checkForUpdates = async () => {
if (__DEV__) {
console.debug('checkForUpdates disabled in DEV');
return;
}
try {
const update = await Updates.checkForUpdateAsync();
console.debug('checkForUpdates result', update);
if (update.isAvailable) {
View alertAsync.js
import { Alert } from 'react-native';
// An alert implementation that returns a promise when the choise is done
export const AlertAsync = (
title,
message,
buttons = [],
options = {},
type,
) => {
View UpdatableContextProvider.js
import React from 'react';
// Permit to create a provider/consumer but allow the consumer
// to also receive a setter to update the provider value
export const createUpdatableContext = () => {
const { Provider, Consumer } = React.createContext(null);
class UpdatableContextProvider extends React.Component {
constructor(props) {
super(props);
View provideAppAsyncData.js
import React from 'react';
import { AppLoading } from 'expo';
import { Centered } from 'common/components/utils/Layout';
import { BaseText } from 'common/styleguide/texts';
import SimpleButton from 'common/components/buttons/SimpleButton';
import CustomSafeAreaView from 'common/components/utils/CustomSafeAreaView';
import { reportError } from 'AppSentry';
const TechnicalErrorScreen = ({ onRetry }) => (
<CustomSafeAreaView>
View Separator.js
import React, { Component } from 'react';
import {View} from "glamorous-native";
import * as Colors from "colors";
import {getColor} from "colors";
import { greyD } from "colors";
const Separator = ({
View injectFiltersAPI.js
const injectFiltersAPI = Comp => {
class FiltersAPIInjector extends React.Component {
constructor() {
super();
this.filtersAPI = {
getFilters: this.getFilters,
setFilters: this.setFilters,
deleteFilters: this.deleteFilters,
@slorber
slorber / Lazy.js
Created Apr 23, 2018
Lazy react native comp
View Lazy.js
import React from 'react';
import {InteractionManager, ActivityIndicator} from 'react-native';
import {View} from 'glamorous-native';
const DefaultLoader = (
<View padding={20} alignItems="center" justifyContent="center">
<ActivityIndicator size="large"/>
</View>
);
View gist:7f59bdff579aa89c7f3700a4c96a071a
✘-127 ~/Desktop/Stample-react-clone [master|✔]
16:25 $ ./node_modules/.bin/now build --config zeit.json --alias frontend-prod.stample.co
Deprecated! The option --alias will be removed soon.
Read more about the new way here: http://bit.ly/2l2v5Fg
> Deploying ~/Desktop/Stample-react-clone/build
> Using Node.js 7.6.0 (default)
> Ready! https://stample-front-sbonzcnqdg.now.sh (copied to clipboard) [2s]
> Initializing…
You can’t perform that action at this time.