Created
October 5, 2018 09:25
-
-
Save hiquest/6ebb95f74f02d51cf3eced051a34efab to your computer and use it in GitHub Desktop.
No this in React
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' | |
// ... other imports | |
import nothis from '../shared/nothis' | |
export default nothis({ | |
willMount, | |
render, | |
}) | |
function render({ state: { loading, card }, setState }) { | |
return ( | |
<div className="card"> | |
{ loading && <Spinner /> } | |
{ !loading && ( | |
<div> | |
<span>{ card.name }</span> | |
<a onClick={remove}>Remove</a> | |
</div> | |
) } | |
<span>{ card.name }</span> | |
</div> | |
) | |
async function remove() { | |
setState({ loading: true }) | |
await remove(card.id) | |
setState({ loading: false, card: undefined}) | |
} | |
} | |
async function willMount({ setState }) { | |
setState({ loading: true }) | |
const card = await fetchCard() | |
setState({ card, loading: false }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment