Next.js Discord

Discord Forum

Functions cannot be passed directly to Client Components unless you explicitly expose it by marking

Answered
Caillou posted this in #help-forum
Open in Discord
Avatar
Using the following code in compilation returns the error, but everything is ok, does anyone have any suggestions?

'use server'
import React from 'react';

export default async function Home() {
    async function action(formData: FormData) {
        'use server'

        console.log('test');
    }

    return (<>
        <div className='flex h-screen w-full justify-center items-center bg-[#ededed]'>
            <div className='border w-1/5 pb-8 shadow-lg rounded text-[#727272] font-semibold bg-white'>
                <div>
                    <form action={action} className='w-11/12 mx-auto pt-8 grid grid-cols-12 gap-x-6 gap-y-3'>
                        <div className='flex flex-col col-span-6'>
                            <label htmlFor='name' className='text-xs'>Name</label>
                            <input name="name" type='text' className='border rounded-lg h-8 focus:outline-none pl-3 invalid:border-red-500' />
                        </div>
                        <div className='flex flex-col col-span-6'>
                            <label htmlFor='bannerURL' className='text-xs'>Banner URL</label>
                            <input name="bannerURL" type='text' className='border rounded-lg h-8 focus:outline-none pl-3 invalid:border-red-500' />
                        </div>
                        <div className='col-span-12 flex'>
                            <div className='flex justify-end float-right w-full'>
                                <button type='submit' className='bg-[#00c882] h-8 rounded-full mt-4 text-white w-32'>Reset</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div >
        </div >
    </>)
}
Answered by Kawakawa
Get rid of the 'use server' line at the top of the file?
View full answer

3 Replies

Avatar
Kawakawa
Get rid of the 'use server' line at the top of the file?
Answer
Avatar
Kawakawa
See if that works
Avatar
ty