Skip to content

Instantly share code, notes, and snippets.

@viniciusdacal
Created February 7, 2018 22:39
Show Gist options
  • Select an option

  • Save viniciusdacal/b98c7e5d197b0c897b15238c2b726eeb to your computer and use it in GitHub Desktop.

Select an option

Save viniciusdacal/b98c7e5d197b0c897b15238c2b726eeb to your computer and use it in GitHub Desktop.
const handlers = {
number: value => <NumberDisplay>{value}</NumberDisplay>
currency: value => <CurrencyDisplay customProps value={value} />
time: value => <TimeDisplay time={value} customProps />
date: value => <DateDisplay date={value} showTime={false} />
default: value => value,
};
const displayData = (type, value) => {
const handler = handlers[type] || handlers.default;
return handler(value);
};
const DataDisplay = ({ type, value }) => (
<div>
{displayData(type, value)}
</div>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment