Nextjs14 and Whereby lib Navigator is not defined
Answered
F1 posted this in #help-forum
F1OP
Hey everybody i use Nextjs14 and whereby lib but i have a problem.
When i call useRoomconnection
it got this error
please give me an advice
When i call useRoomconnection
const roomConnection = useRoomConnection(ROOM_URL, {
localMediaOptions: {
audio: true,
video: true,
}
});it got this error
navigator is not definedplease give me an advice
Answered by Ray
navigator is browser api which isn't available on the server.you could create a component and use
useRoomConnection hook in it. Then use dynamic with ssr disable to import itimport dynamic from 'next/dynamic';
const RoomConnection = dynamic(() => import('./room-connection'), {ssr:false})
export default function TempPage() {
return <RoomConnection />
}15 Replies
@F1 Hey everybody i use Nextjs14 and whereby lib but i have a problem.
When i call useRoomconnection
const roomConnection = useRoomConnection(ROOM_URL, {
localMediaOptions: {
audio: true,
video: true,
}
});
it got this error
navigator is not defined
please give me an advice
navigator is browser api which isn't available on the server.you could create a component and use
useRoomConnection hook in it. Then use dynamic with ssr disable to import itimport dynamic from 'next/dynamic';
const RoomConnection = dynamic(() => import('./room-connection'), {ssr:false})
export default function TempPage() {
return <RoomConnection />
}Answer
F1OP
wow first of all i'm a big fan of messi too haha thank you so much.
but i'm new at react and nextjs so i have a questions about how to create RoomConnection component .
If i create a component with useRoomConnection. How to use thing that come from room connection properties such as actions, toggleMicrophone please give me an example bro.
@Ray
but i'm new at react and nextjs so i have a questions about how to create RoomConnection component .
If i create a component with useRoomConnection. How to use thing that come from room connection properties such as actions, toggleMicrophone please give me an example bro.
const roomConnection = useRoomConnection(ROOM_URL, {
localMediaOptions: {
audio: true,
video: true,
}
});
const { actions } = roomConnection;
const { toggleMicrophone } = actions;@Ray
@F1 wow first of all i'm a big fan of messi too haha thank you so much.
but i'm new at react and nextjs so i have a questions about how to create RoomConnection component .
If i create a component with useRoomConnection. How to use thing that come from room connection properties such as actions, toggleMicrophone please give me an example bro.
const roomConnection = useRoomConnection(ROOM_URL, {
localMediaOptions: {
audio: true,
video: true,
}
});
const { actions } = roomConnection;
const { toggleMicrophone } = actions;
<@743561772069421169>
just create a new file
// app/temp-page/room-connection.tsx
'use client'
export default function RoomConnection() {
const roomConnection = useRoomConnection(ROOM_URL, {
localMediaOptions: {
audio: true,
video: true,
}
});
const { actions } = roomConnection;
const { toggleMicrophone } = actions;
...
}F1OP
thank a lot bro can you explain me why it work ?? @Ray
@F1 thank a lot bro can you explain me why it work ?? <@743561772069421169>
because when the page try to render on the server and the
when using
navigator is not available so you see the error.when using
dynamic with ssr disable, this component will not be rendered on the server and only render on clientF1OP
I want my page render on client too.
Why my page try to render on the server?
Why my page try to render on the server?
@F1 I want my page render on client too.
Why my page try to render on the server?
your page will render on client
because nextjs will prerender the page on the server
@Ray your page will render on client
F1OP
because i use 'use client' at the top of my TempPage ?
@F1 because i use 'use client' at the top of my TempPage ?
'use client' will mark the component as client component@Ray your page will render on client
F1OP
my page will render on client because the page is component and i use 'use client' at the top of my TempPage ?
Did I understand correctly?
Did I understand correctly?
yes
F1OP
thanks a lot bro god bless you.