This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyFirstFunctionalComponent = (props) => { | |
return ( | |
<div> | |
{props.num + props.multiplier} | |
</div> | |
) | |
} | |
class MyFirstClassComponent extends React.Component { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/getHeadlines.js | |
export default () => { | |
// do stuff | |
} | |
// __tests__/myTest.js | |
import getHeadlines from '../src/getHeadlines' | |
jest.mock('../src/getHeadlines', () => (user, type) => ({ // notice that the mocked function is the return of an initial function | |
data: [user, type, 'misc'] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify('production') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const json = `{ | |
"Status": "Success", | |
"Errors": [], | |
"Paging": [], | |
"Notices": [], | |
"Message": null, | |
"Data": { | |
"certifications": [ | |
{ | |
"name": "American Standard Certification", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const job1 = cb => setTimeout(() => cb('first'), 900) | |
const job2 = cb => setTimeout(() => cb('second'), 100) | |
const job3 = cb => setTimeout(() => cb('third'), 300) | |
const jobs = [job1, job2, job3] | |
const asyncMap = (jobs, callback) => { | |
const jobPromises = jobs.map(job => { // loop through jobs | |
return new Promise((resolve, reject) => { // return a promise for each item in the array | |
return job(resolve) // resolve each promise to the value passed to cb() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends React.Component { | |
render() { | |
// <View> will expand to the dimensions of DropZone within it | |
return <View ref={view => { this.myComponent = view; }}><DropZone /></View> | |
} | |
componentDidMount() { | |
this.myComponent.measure((x, f, width, height, px, py) => { | |
console.log('MyComponent width is: ' + width) | |
console.log('MyComponent height is: ' + height) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = (arr, reducer, initVal) => new Promise((resolve, reject) => { | |
let i = 0; | |
const next = total => { | |
const item = arr[i]; | |
if (!item) { | |
resolve(total); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import api from './api' | |
const routesMap = { | |
HOME: '/', // path only route | |
LIST: { // route object (with a path) | |
path: '/list/:slug', | |
thunk: async (dispatch, getState) => { | |
const { slug } = getState().location.payload | |
const response = await fetch(`/api/items/${slug}`) | |
const items = await data.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const history = createHistory({ | |
getUserConfirmation(message, callback) { | |
confirmationDialog(message, (res) => { | |
shouldChange = !!res | |
callback(res) | |
}) | |
} | |
}) | |
history.block((location, action) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const routesMap = { | |
ADMIN: { | |
path: '/admin', | |
role: 'admin' | |
} | |
} |