Skip to content

Instantly share code, notes, and snippets.

@fakenickels
Created February 21, 2018 20:00
Show Gist options
  • Select an option

  • Save fakenickels/58dc4e1e0aa534dbbd41bd6401f4e443 to your computer and use it in GitHub Desktop.

Select an option

Save fakenickels/58dc4e1e0aa534dbbd41bd6401f4e443 to your computer and use it in GitHub Desktop.
import { compose, withStateHandlers, withHandlers } from 'recompose'
export default compose(
withStateHandlers({
isFetching: false,
name: '',
data: null
}, {
setFetching: (state) => (isFetching) => ({ ...state, isFetching }),
setData: (state) => (data) => ({ ...state, data }),
setName: (state) => name => ({ ...state, name }),
}),
withHandlers({
fetchPokemon: (props) => () => {
props.setFetching(true)
fetch(`https://pokeapi.co/api/v2/pokemon/${props.name}`)
.then(res => res.json())
.then(response => {
props.setFetching(false)
props.setData(response)
})
}
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment