feat: auth & admin
This commit is contained in:
@@ -12,21 +12,24 @@ Effect Event functions do not have a stable identity. Their identity intentional
|
||||
**Incorrect (Effect Event added as a dependency):**
|
||||
|
||||
```tsx
|
||||
import { useEffect, useEffectEvent } from 'react'
|
||||
import { useEffect, useEffectEvent } from 'react';
|
||||
|
||||
function ChatRoom({ roomId, onConnected }: {
|
||||
roomId: string
|
||||
onConnected: () => void
|
||||
function ChatRoom({
|
||||
roomId,
|
||||
onConnected,
|
||||
}: {
|
||||
roomId: string;
|
||||
onConnected: () => void;
|
||||
}) {
|
||||
const handleConnected = useEffectEvent(onConnected)
|
||||
const handleConnected = useEffectEvent(onConnected);
|
||||
|
||||
useEffect(() => {
|
||||
const connection = createConnection(roomId)
|
||||
connection.on('connected', handleConnected)
|
||||
connection.connect()
|
||||
const connection = createConnection(roomId);
|
||||
connection.on('connected', handleConnected);
|
||||
connection.connect();
|
||||
|
||||
return () => connection.disconnect()
|
||||
}, [roomId, handleConnected])
|
||||
return () => connection.disconnect();
|
||||
}, [roomId, handleConnected]);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -35,21 +38,24 @@ Including the Effect Event in dependencies makes the effect re-run every render
|
||||
**Correct (depend on reactive values, not the Effect Event):**
|
||||
|
||||
```tsx
|
||||
import { useEffect, useEffectEvent } from 'react'
|
||||
import { useEffect, useEffectEvent } from 'react';
|
||||
|
||||
function ChatRoom({ roomId, onConnected }: {
|
||||
roomId: string
|
||||
onConnected: () => void
|
||||
function ChatRoom({
|
||||
roomId,
|
||||
onConnected,
|
||||
}: {
|
||||
roomId: string;
|
||||
onConnected: () => void;
|
||||
}) {
|
||||
const handleConnected = useEffectEvent(onConnected)
|
||||
const handleConnected = useEffectEvent(onConnected);
|
||||
|
||||
useEffect(() => {
|
||||
const connection = createConnection(roomId)
|
||||
connection.on('connected', handleConnected)
|
||||
connection.connect()
|
||||
const connection = createConnection(roomId);
|
||||
connection.on('connected', handleConnected);
|
||||
connection.connect();
|
||||
|
||||
return () => connection.disconnect()
|
||||
}, [roomId])
|
||||
return () => connection.disconnect();
|
||||
}, [roomId]);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user