This file contains hidden or 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 React from 'react' | |
| class App extends React.Component { | |
| constructor(props) { | |
| super(props) | |
| this.state = { | |
| items: props.items, | |
| } | |
| } | |
| } |
This file contains hidden or 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 React from 'react' | |
| class App extends React.Component { | |
| constructor(props) { | |
| super(props) | |
| // Initialize the state on mount | |
| this.state = { | |
| items: props.items, | |
| } | |
| } |
This file contains hidden or 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 App = ({ items = [] }) => ( | |
| <div> | |
| <h2>Here are your items:</h2> | |
| <div> | |
| {items.length && | |
| items.map((item) => <div key={item.label}>{item.label}</div>)} | |
| </div> | |
| </div> | |
| ) |
This file contains hidden or 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 App = ({ items = [] }) => ( | |
| <div> | |
| <h2>Here are your items:</h2> | |
| <div> | |
| {!!items.length && | |
| items.map((item) => <div key={item.label}>{item.label}</div>)} | |
| </div> | |
| </div> | |
| ) |
This file contains hidden or 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 something = (state) => { | |
| let newState = { ...state } | |
| const indexPanda = newState.items.indexOf('panda') | |
| if (indexPanda !== -1) { | |
| newState.items.splice(indexPanda, 1) | |
| } | |
| return newState | |
| } | |
| const initialState = { |
This file contains hidden or 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 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} /> | |
| } |
This file contains hidden or 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
| <ModalComponent | |
| open={aFormIsOpened} | |
| onClose={() => closeModal(formName)} | |
| arial-labelledby={`${formName}-modal`} | |
| arial-describedby={`${formName}-modal`} | |
| classes={{ | |
| root: cx(classes.modal, { [classes.dialog]: shouldUseDialog }), | |
| ...additionalDialogClasses, | |
| }} | |
| disableAutoFocus |
This file contains hidden or 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 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> |
This file contains hidden or 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 someFunction = function() { | |
| return { | |
| names: ['bob', 'joe'], | |
| foods: ['apple', 'pineapple'], | |
| } | |
| } | |
| const obj = someFunction() | |
| const names = obj['names'] |
This file contains hidden or 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 someFunction = function() { | |
| return { | |
| names: ['bob', 'joe'], | |
| foods: ['apple', 'pineapple'], | |
| } | |
| } | |
| const obj = someFunction() | |
| const names = obj['names'] |