UNPKG

1.12 kBTypeScriptView Raw
1import React, { Component } from 'react';
2import { Platform, Text, View } from 'react-native';
3
4import {
5 default as withProductDetailData,
6 WithProductDetailProps,
7 WithProductDetailProviderProps
8} from './ProductDetailProvider';
9
10import {
11 CommerceDataSource,
12 CommerceTypes
13} from '@brandingbrand/fscommerce';
14
15export interface UnwrappedProductDetailProps {
16 id: string;
17}
18
19export type ProductDetailProduct = CommerceTypes.Product;
20export type ProductDetailProps = UnwrappedProductDetailProps & WithProductDetailProviderProps;
21
22class ProductDetail extends Component<UnwrappedProductDetailProps & WithProductDetailProps> {
23 render(): JSX.Element {
24 const data = JSON.stringify(this.props.commerceData, null, 2);
25 if (Platform.OS === 'web') {
26 return <pre>{data}</pre>;
27 } else {
28 return (
29 <View>
30 <Text>{data}</Text>
31 </View>
32 );
33 }
34 }
35}
36
37export default withProductDetailData<UnwrappedProductDetailProps>(
38 async (DataSource: CommerceDataSource, props: UnwrappedProductDetailProps) => {
39 return DataSource.fetchProduct(props.id);
40 }
41)(ProductDetail);