Skip to content

Instantly share code, notes, and snippets.

import React from 'react'
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
items: props.items,
}
}
}
import React from 'react'
class App extends React.Component {
constructor(props) {
super(props)
// Initialize the state on mount
this.state = {
items: props.items,
}
}
const App = ({ items = [] }) => (
<div>
<h2>Here are your items:</h2>
<div>
{items.length &&
items.map((item) => <div key={item.label}>{item.label}</div>)}
</div>
</div>
)
const App = ({ items = [] }) => (
<div>
<h2>Here are your items:</h2>
<div>
{!!items.length &&
items.map((item) => <div key={item.label}>{item.label}</div>)}
</div>
</div>
)
const something = (state) => {
let newState = { ...state }
const indexPanda = newState.items.indexOf('panda')
if (indexPanda !== -1) {
newState.items.splice(indexPanda, 1)
}
return newState
}
const initialState = {
const Parent = (props) => {
if (props.user && props.user.email) {
// Fire some redux action to update something globally that another
// component might need to know about
}
// Continue on with the app
return <Child {...props} />
}
<ModalComponent
open={aFormIsOpened}
onClose={() => closeModal(formName)}
arial-labelledby={`${formName}-modal`}
arial-describedby={`${formName}-modal`}
classes={{
root: cx(classes.modal, { [classes.dialog]: shouldUseDialog }),
...additionalDialogClasses,
}}
disableAutoFocus
const SomeComponent = ({ items = [], todaysDate, tomorrowsDate }) => {
const [someState, setSomeState] = useState(null)
return (
<div>
<h2>Today is {todaysDate}</h2>
<small>And tomorrow is {tomorrowsDate}</small>
<hr />
{items.map((item, index) => (
<span key={`item_${index}`}>{item.email}</span>
const someFunction = function() {
return {
names: ['bob', 'joe'],
foods: ['apple', 'pineapple'],
}
}
const obj = someFunction()
const names = obj['names']
const someFunction = function() {
return {
names: ['bob', 'joe'],
foods: ['apple', 'pineapple'],
}
}
const obj = someFunction()
const names = obj['names']