React
This guide walks you through integrating OneSDK with React, providing you with a solid foundation for building secure and efficient KYC workflows.
Quick Start
Configuration
Vite Configuration
Add this configuration to your vite.config.js
:
Environment Setup
Based on your build tool and/or framework, you may have a different prefix to the environment variables, e.g. if you’re using Vite, your env prefix is going to be “VITE_” instead of “REACT_APP_“
Create a .env
file with your credentials:
Integration with React
Custom Hook Implementation
useOneSDK Hook
Usage Example
Best Practices
Error Handling
- Always handle token generation errors - Provide meaningful error messages
- Implement proper error boundaries
Security
- Never expose API keys in client-side code
- Use environment variables
- Implement proper token management
Performance
- Use React.memo for expensive renders
- Implement proper cleanup in
useEffect
- Avoid unnecessary re-renders
State Management
- Use proper state management patterns
- Implement loading states
- Handle edge cases properly
Remember to handle token expiration and implement proper refresh mechanisms in a production environment.
Troubleshooting
Common Issues
- Token Generation Fails: Verify your credentials and network connection
- SDK Initialization Errors: Check configuration object format
- Component Re-rendering: Implement proper memoization
Environment Variables
- Vite: Ensure variables are prefixed with
VITE_
- Create React App: Ensure variables are prefixed with
REACT_APP_
- Development: Verify
.env
file location