Skip to content

Instantly share code, notes, and snippets.

@dyrkow
Last active March 3, 2023 08:13
Show Gist options
  • Save dyrkow/6162e36613c836848b484e1e797f5a90 to your computer and use it in GitHub Desktop.
Save dyrkow/6162e36613c836848b484e1e797f5a90 to your computer and use it in GitHub Desktop.
2. Решаем проблему с крашем всего приложения в пользу краша конкретной БОЛЬШОЙ части интерефейса, с возможностью исправить проблему вручную
<div>
<ErrorBoundary>
<ProfileScreen />
</ErrorBoundary>
<ErrorBoundary title="Ошибка!" description="Что-то случилось" action={(props) => <Button onPress={props.onRefresh}>Повторить</Button>}>
<OrderItems />
</ErrorBoundary>
<ErrorBoundary>
<OrderList />
</ErrorBoundary>
</div>
4. Решаем проблему с фичами, теперь чтобы скрыть какую-то возможность лучше использовать HOC компонент
<Feature name="user.can.delete.sale_point" enabled>
<FeatureUserCanDeleteSalePoint />
</Feature>
<Feature name="user.can.delete.sale_point" disabled>
<FeatureUserCanDeleteSalePoint />
</Feature>
<Feature name="user.can.delete.sale_point" enabled andUserRoles={["admin", "director"]}>
<FeatureUserCanDeleteSalePoint />
</Feature>
import React from 'react';
type ForProps<TElement> = {
of: TElement[];
render: (el: TElement, index: number) => JSX.Element;
}
/**
* Use for render array of data elements
*
* @example
*
* const NumberView = ({ item, index }) => <Text>{item}</Text>;
*
* <For<number> of={[1,2,3,4,5]} render={NumberView}>
*/
export const For = <T,>({ of, render }: ForProps<T>): JSX.Element => <>{of.map(render)}</>;
import React from 'react';
type IfProps = {
children: React.ReactElement<any>;
value: boolean;
otherwise?: JSX.Element;
}
/**
* Used for conditional rendering
*
* @example
*
* <If value={user.age > 18} otherwise={<BabyAlert messsage="You so baby"/>}>
* <Show18+ />
* </If>
*/
export const If = ({ value = true, children, otherwise = null}: IfProps): JSX.Element => value ? children : otherwise;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment