docs: improve userAgent device.type example in userAgent.mdx (#78368)
### What?
Updates the `userAgent` middleware example in the documentation to
accurately reflect all possible values of `device.type` and demonstrate
proper handling of desktop browsers (undefined case).
### Why?
The current example shows a binary mobile/desktop check which doesn't
accurately reflect the API's capabilities. The `device.type` property
can actually return multiple values ('mobile', 'tablet', 'console',
'smarttv', 'wearable', 'embedded', or undefined), but the example only
shows handling of 'mobile', which could mislead developers.
### How?
- Updated both TypeScript and JavaScript examples to:
1. Add comprehensive comments documenting all possible `device.type`
values
2. Use proper undefined handling with the OR operator for desktop
browsers
3. Maintain consistency between TS and JS versions
4. Better align with the documented behavior in the API reference
- Ran `pnpm prettier-fix` to ensure proper formatting
- Followed the [Docs Contribution
Guide](https://nextjs.org/docs/community/contribution-guide)
The changes help developers better understand:
- The full range of device types they can detect
- How desktop browsers return undefined
- The proper way to handle device type detection
- Consistency with the rest of the API documentation
### Checklist
- [x] Read the [Docs Contribution
Guide](https://nextjs.org/docs/community/contribution-guide)
- [x] Ran `pnpm prettier-fix` to fix formatting issues
- [x] Ensured examples are clear and follow documentation best practices
- [x] Maintained consistency with existing documentation style
- [x] Verified the accuracy of the technical information
---------
Co-authored-by:
JJ Kasper <jj@jjsweb.site>
Showing
Please
register
or
sign in
to comment