Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Sébastien Lorber slorber

🏠
Working from home
View GitHub Profile
@slorber
slorber / README.md
Created Jul 13, 2020
React Hebdo #21
View README.md

React Hebdo #21

Mettez un commentaire:

  • si vous recrutez
  • si vous cherchez un travail ou une mission
  • pour commenter un article
  • pour donner un avis sur la newsletter
@slorber
slorber / README.md
Last active Sep 22, 2020
React Hebdo 2020
View README.md

React Hebdo 2020

Je teste un système de "petites annonces". Le même Gist sera utilisé sur plusieurs éditions.

Mettez un commentaire:

  • si vous recrutez
  • si vous cherchez un travail ou une mission
  • pour commenter un article
  • pour donner votre avis sur la newsletter
View intersperse-flatmap.ts
export const intersperse = <T>(arr: T[], separator: (n: number) => T): T[] =>
arr.flatMap(arr, (a, i) => i > 0 ? [separator(i-1), a] : [a]))
@slorber
slorber / react-navigation-tree.jsx
Last active Sep 9, 2020
react-navigation-tree.jsx
View react-navigation-tree.jsx
const App = createAppContainer(
createStack({
LoggedSwitch: createSwitch({
// When user is authenticated
LoggedIn: createStack({
// The logged in root is generally a tab or drawer navigator
LoggedInRoot: createTabsOrDrawer({
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>
You can’t perform that action at this time.