React
Learn how to use Permix with React applications
Overview
Permix provides official React integration through the PermixProvider
component and usePermix
hook. This allows you to manage permissions reactively in your React app.
Before getting started with React integration, make sure you've completed the initial setup steps in the Quick Start guide.
Setup
First, wrap your application with the PermixProvider
:
Remember to always pass the same Permix instance to both the PermixProvider
and usePermix
hook to maintain type safety.
Hook
For checking permissions in your components, you can use the usePermix
hook. And to avoid importing the hook and Permix instance in every component, you can create a custom hook:
Components
If you prefer using components, you can import the createComponents
function from permix/react
and create checking components:
And then you can use the Check
component in your components: