Skip to content
Advertisement

NextJS 13 Event handlers cannot be passed to Client Component props

NextJS Error Message

Error: Event handlers cannot be passed to Client Component props. ^^^^^^^^^^ If you need interactivity, consider converting part of this to a Client Component.

const reqHelp = () => {
    Swal.fire({
        title: '1',
        text: '1',
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes',
        cancelButtonText: 'No',
    })
}
return(
        <div className="buttons">
            <button onClick={reqHelp} className="stopwatchButton">Request Help</button>
        </div>
);

Search NextJS 13 Official Document and about Server/Client Render

Advertisement

Answer

Add ‘use client’ on top of the file where you are using handleClick because all components in Next 13 by default are server components, therefore for client side interactivity you need to use “use client”.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement