Fix useEffect hook for product fetching in CreateRecipePage component
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { fetchJson } from '../../../lib/api';
|
import { fetchJson } from '../../../lib/api';
|
||||||
|
|
||||||
@@ -16,8 +16,7 @@ export default function CreateRecipePage() {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
// Hämta produkter vid sidladdning
|
useEffect(() => {
|
||||||
useState(() => {
|
|
||||||
fetchJson('/api/products')
|
fetchJson('/api/products')
|
||||||
.then(setProducts)
|
.then(setProducts)
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
|
|||||||
Reference in New Issue
Block a user