Created
March 18, 2020 01:06
-
-
Save anderjs/9a0223ec49b50ea47f1d1bc318cc1eac to your computer and use it in GitHub Desktop.
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 { 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