A collection of React hooks commonly used in Decentraland projects.
npm install @dcl/hooks
useAdvancedUserAgentData
: Enhanced user agent informationuseAsyncState
: Async state management with dependenciesuseAsyncTask
: Single async task managementuseAsyncTasks
: Multiple async tasks managementusePatchState
: Partial state updates for complex objectsuseAsyncEffect
: Async version of useEffectuseAsyncMemo
: Async version of useMemo
import { useAsyncState } from '@dcl/hooks'
function Example() {
const [data, { loading, error }] = useAsyncState(
async () => {
const response = await fetch('https://api.example.com/data')
return response.json()
},
[] // dependencies
)
if (loading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return <div>{JSON.stringify(data)}</div>
}
import { useAdvancedUserAgentData } from '@dcl/hooks'
function BrowserInfo() {
const [isLoading, data] = useAdvancedUserAgentData()
if (isLoading) return <div>Loading browser info...</div>
return (
<div>
<h3>Browser Information</h3>
<ul>
<li>Browser: {data?.browser.name} {data?.browser.version}</li>
<li>OS: {data?.os.name} {data?.os.version}</li>
<li>CPU Architecture: {data?.cpu.architecture}</li>
<li>Mobile Device: {data?.mobile ? 'Yes' : 'No'}</li>
</ul>
</div>
)
}
This project is licensed under the MIT License - see the LICENSE file for details.