Skip to content

Instantly share code, notes, and snippets.

@anderjs
Created March 18, 2020 01:06
Show Gist options
  • Select an option

  • Save anderjs/9a0223ec49b50ea47f1d1bc318cc1eac to your computer and use it in GitHub Desktop.

Select an option

Save anderjs/9a0223ec49b50ea47f1d1bc318cc1eac to your computer and use it in GitHub Desktop.
import { useEffect, useState } from 'react'
function usePermissions () {
const [permission, setPermission] = useState({})
const getPermissions = useCallback(() => {
fetch('....', { ...headers })
.then(data => data.json())
.then(permissions => setPermission({ ...permissions.response })
.catch(err => // do something with the error)
}, [])
useEffect(getPermissions, [getPermissions])
return [permission]
}
const View = () => {
const [permissions] = usePermissions()
return (
<React.Fragment>
{permissions.delete && <button>Eliminar</button>}
{permissions.edit && <button>Editar</button>}
</React.Fragment>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment