Skip to content

Instantly share code, notes, and snippets.

@innerdaze
Last active February 27, 2018 16:49
Show Gist options
  • Save innerdaze/b83aed476d09b839ff094090eaabd0cb to your computer and use it in GitHub Desktop.
Save innerdaze/b83aed476d09b839ff094090eaabd0cb to your computer and use it in GitHub Desktop.
Different Component Structure with Ramda
import React from 'react'
import { map, apply, zip, times } from 'ramda'
import { v4 } from 'uuid'
import Box from 'grommet/components/Box'
const propArray = [
'Supplier Code',
'PackSize',
'In Stock',
'On Order',
'Avg Weekly Sales'
]
const renderItemDetailPair = (key, prop, value) => (
<Box key={key} margin={{ right: 'medium' }} flex='grow'>
<span style={{ color: '#6b6b6b', fontWeight: 600 }}>{prop}</span> {value}
</Box>
)
const applyDataToRender = apply(renderItemDetailPair)
const keyAndPropsArray = zip(times(v4, propArray.length), propArray)
const mergeValuesIntoProps = (values, props) => {
values.forEach((item, index) => props[index].push(item))
return props
}
const OrderMeta = ({
order: { product: { SupplierID, PackSize, CurrStock, OnOrder, AvgSales } }
}) =>
map(
applyDataToRender,
mergeValuesIntoProps(
[SupplierID, PackSize, CurrStock, OnOrder, AvgSales],
keyAndPropsArray
)
)
export default OrderMeta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment