Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Last active October 27, 2018 16:26
Show Gist options
  • Save ernestofreyreg/7145e90376cb26212acc610dc82f1ba2 to your computer and use it in GitHub Desktop.
Save ernestofreyreg/7145e90376cb26212acc610dc82f1ba2 to your computer and use it in GitHub Desktop.
import React from 'react'
import ReactDOM from 'react-dom'
import useStateManager from './useStateManager'
import createUrlLoader from './state'
const LogicReuse = () => {
const [userState, userActions] = useStateManager(
createUrlLoader('https://api.github.com/users/ernestofreyreg')
)
return (
<div className='App'>
{userState.loading
? <div>Loading</div>
: <div>{JSON.stringify(userState.data || userState.error)}</div>
}
<button onClick={userActions.loadData}>Load User</button>
</div>
)
}
ReactDOM.render(<LogicReuse />, document.getElementById('root'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment