Skip to content

Instantly share code, notes, and snippets.

@viniciusdacal
Last active January 13, 2018 04:36
Show Gist options
  • Save viniciusdacal/3c435cf572b15dba29adab44a89a707e to your computer and use it in GitHub Desktop.
Save viniciusdacal/3c435cf572b15dba29adab44a89a707e 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 MyComponent = ({ type, value }) => (
<div>
<h1>I have some content here</h1>
{displayData(type, value)}
</div>
)
@alur222
Copy link

alur222 commented Jan 13, 2018

nice! hahahaha This is Alur from Fb page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment