Show / Hide Components
The VistaCheck
component dynamically hides child components if the current user does not have the specified permissions. You can optionally render an alternate component if access is denied.
#
Usageimport { VistaProvider, VistaCheck } from '@vista.io/react-vista-js';
// how to generate 'read tokens' https://docs.govista.io/Guides/React%20Components/Authentication<VistaProvider secret={read_token}> <VistaCheck user_id={user_id} action={action} resource_type={resource_type} resource_id={resource_id} branch="test"
// optional denyComponent={<React.Fragment />} // rendered if permission denied handleError={(err) => console.log(err)}> <WrappedComponent></WrappedComponent> </VistaCheck></VistaProvider>
The component will hit the Vista API to determine if user_id
can perform action
on resource_id
. If granted, only then will the child component render. If not granted, the denyComponent
is rendered if supplied, otherwise nothing is rendered.
See the client library docs on how to generate read_token
.