Skip to content

Instantly share code, notes, and snippets.

View viniciusdacal's full-sized avatar

Vinicius Dacal viniciusdacal

View GitHub Profile
const UserList = ({ isLoading, results }) => (
<div>
<div>
<h1>Users</h1>
<a href="/users/create">New User</a>
</div>
<div>
{isLoading && <span>Loading...</span>}
{!isLoading && !results.length && (
const user = {
name: 'John',
surname: 'Doe',
address: null,
};
const userName = user && user.name // John
const address = user && user.address // null
const zipCode = user && user.address && user.address.zipcode // null
const UserList = ({ isLoading, results }) => (
<div>
<div>
<h1>Users</h1>
<a href="/users/create">New User</a>
</div>
<div>
{isLoading && <span>Loading...</span>}
{!isLoading && (
const UserList = ({ isLoading, results }) => {
if (isLoading) {
return <span>Loading...</span>
}
return (
<ul>
{result.map((user) => (
<li>{user.name}</li>
))}
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;
// Helper to swap between localStorage and cookie storage due to stupid Safari
import Cookie from 'js-cookie';
const storage = {};
// Safari in incognito has local storage, but size 0
// This system falls back to cookies in that situation
try {
if (!window.localStorage) {
throw Error('no local storage');
const channelLabel = (channelKey) => {
switch(channelKey) {
case 'tv':
return 'TV/OTT';
case 'youtube':
return 'Youtube';
case 'instagram':
return 'Instagram';
default:
return 'Default value'
import { configure } from '@storybook/react';
const reqSrc = require.context('../src', true, /.stories.jsx$/);
function loadStories() {
reqSrc.keys().forEach(filename => reqSrc(filename));
}
configure(loadStories, module);
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import Button from './Button';
storiesOf('Button', module)
.add('default', () => (
<Button onClick={action('clicked')}>Hello Button</Button>
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import Button from '../Button/Button';
storiesOf('Button', module)
.add('default', () => (
<Button onClick={action('clicked')}>Hello Button</Button>