Next.js Discord

Discord Forum

server side toggle effect ?

Unanswered
Polish posted this in #help-forum
Open in Discord
PolishOP
I have a component that retrieves data from a server or API, which ideally should be a server-side component. Essentially, this component is a page with a button. When this button is clicked, it reveals content that is originally hidden, thus creating a toggling effect. It's important to note that there's no additional request or anything similar on the client-side. Once the HTML is accessible, we aim to add certain interactivity to it, similar to how jQuery events are connected to existing HTML. For instance, if any DOM has a click event, upon clicking, it should display the underlying content that's hidden by default with a hidden class. How can we accomplish this with a server-side component? Do we genuinely require a client-side component for this task? https://tenor.com/view/confused-confusing-noidea-cat-gif-14787244675382286846

3 Replies

Add interactivity and event listeners (onClick(), onChange(), etc)
thats a client component thing, so make a new file and give it the "use client".. do your interactions there and call it from the server component