Edit Blog Page with re-render Issue when the same website is opened on another tab (Nextjs)

8 Views Asked by At

so I had previously used nextjs to create an website but found this bug on the website where on the edit blog page, lets say i open up another tab with the same website either on localhost or on vercel i face the same issue.

async function getData({ search }) {
const res = await fetch(\https://...vercel.app/api/blog/${search})
if (!res.ok) {throw new Error('Failed to fetch data')}
return res.json()}

this is used to fetch data and a usestate react form takes these data and uses them as its values

as const [form, setForm] = useState({ title: data.title, mainImg: data.mainImg, author: data.author, markdown: data.markdown, date: new Date(Date.parse(data.date)), topic: data.topic, pdf: data.pdf })

I have included a preventDefault() method too but it still keeps refreshing continuously when i open the same website on another tab and looses all the changes made in edit blog textarea and gets re-rendered to the data from the database.

I am some what new to nextjs so would like to get some examples..

Thanks

I have tried in different methods by using function call and all but it doesnt seem to help much

0

There are 0 best solutions below