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'; | |
import Storage from 'components/Storage'; | |
class ComponentNeedingStorage extends React.Component { | |
state = { | |
username: '', | |
favoriteMovie: '', | |
isFetching: false, | |
} |
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 Storage extends React.Component { | |
state = { | |
localStorageAvailable: false, | |
}; | |
componentDidMount() { | |
this.checkLocalStorageExists(); | |
} |
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 SharedComponentWithGoofyName extends React.Component { | |
render() { | |
return ( | |
<div> | |
{this.props.wrapThisThingInADiv()} | |
</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
import React from 'react'; | |
import SharedComponent from 'components/SharedComponent'; | |
const SayHello = () => ( | |
<SharedComponent render={() => ( | |
<span>hello!</span> | |
)} /> | |
); | |
// This would return: | |
// <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
import React from 'react'; | |
const SharedComponent extends React.Component { | |
render() { | |
return ( | |
<div> | |
{this.props.render()} | |
</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
import React from 'react'; | |
import withStorage from 'components/withStorage'; | |
class ComponentNeedingStorage extends React.Component { | |
state = { | |
username: '', | |
favoriteMovie: '', | |
} | |
componentDidMount() { |
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'; | |
const withStorage = (WrappedComponent) => { | |
class HOC extends React.Component { | |
state = { | |
localStorageAvailable: false, | |
}; | |
componentDidMount() { | |
this.checkLocalStorageExists(); |
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'; | |
import withSecretToLife from 'components/withSecretToLife'; | |
const DisplayTheSecret = props => ( | |
<div> | |
The secret to life is {props.secretToLife}. | |
</div> | |
); | |
const WrappedComponent = withSecretToLife(DisplayTheSecret); |
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'; | |
const withSecretToLife = (WrappedComponent) => { | |
class HOC extends React.Component { | |
render() { | |
return ( | |
<WrappedComponent | |
{...this.props} | |
secretToLife={42} | |
/> |