Skip to content

Instantly share code, notes, and snippets.

@hiquest
Created October 5, 2018 09:25
Show Gist options
  • Save hiquest/6ebb95f74f02d51cf3eced051a34efab to your computer and use it in GitHub Desktop.
Save hiquest/6ebb95f74f02d51cf3eced051a34efab to your computer and use it in GitHub Desktop.
No this in React
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