Next.js Discord

Discord Forum

When using mdx, can I mark a page with `"use client"`?

Unanswered
Chinese Alligator posted this in #help-forum
Open in Discord
Chinese AlligatorOP
Currently I am implementing some MDX pages (https://nextjs.org/docs/app/building-your-application/configuring/mdx). I am using app router. Where in a normal page components I can use 'use client', I am not sure how I can in a mdx-page

'use client'

import Banner from '@/components/Banner/Banner'
import Cards from '@/components/Cards'
import Footer from '@/components/Footer'
import Hero from '@/components/Hero'
import Integration from '@/components/Integration'
import Upload from '@/components/Upload'
import React, { useEffect, useState } from 'react'

const App: React.FC = () => {
  const [hasMounted, setHasMounted] = useState(false)

  useEffect(() => {
    setHasMounted(true)
  }, [])

  if (!hasMounted) {
    return <></>
  }
  return (
    <main className="homepage">
      <Banner />
      <Hero />
      <Cards />
      <Upload />
      <Integration />
      <Footer />
    </main>
  )
}

export default App

12 Replies

Chinese AlligatorOP
Isn't that a potential security incident?
Also it's a bit odd to fetch them through HTTP from myself when I have them locally also
@Chinese Alligator Also it's a bit odd to fetch them through HTTP from myself when I have them locally also
you should be able to directly import them iirc. No it shouldnt be a security issue, as the files are on your server and you have full control over the server. Also the component, that imports the remote mdx component is a server component. So secure as well 👍
Chinese AlligatorOP
Ok, so no client-side fetching is going on? Can I ensure the component is not available client-side somehow?
@Chinese Alligator Ok, so no client-side fetching is going on? Can I ensure the component is not available client-side somehow?
yes, you can add the directive 'server only' on top of your file to prevent leaks
Chinese AlligatorOP
Ah, my specific component is ofcourse somehow a client component ..
Chinese AlligatorOP
Because the top one probably is, because of translations and the fact we use t to translate in other components
TLDR top page components are client, therefore this one is also client.
@Chinese Alligator solved?