Pass data to server action from `useEffect`
Unanswered
piscopancer posted this in #help-forum
nextjs docs suggest this code snippet for server actions. server actions cannot be called as regular functions with parameters, there is no hidden inputs inside this form either, because there is no form. how do i pass dynamic data to a server action then?
'use client'
import { incrementViews } from './actions'
import { useState, useEffect } from 'react'
export default function ViewCount({ initialViews }: { initialViews: number }) {
const [views, setViews] = useState(initialViews)
useEffect(() => {
const updateViews = async () => {
const updatedViews = await incrementViews()
setViews(updatedViews)
}
updateViews()
}, [])
return <p>Total Views: {views}</p>
}5 Replies
you can call server actions with params tho?
am I tripping or smthing
well i may be confusing sometjing as well, ngl@averydelusionalperson
so, what's the issue?
you can pass params to server actions