From 4fcbd03565722240ffd10be17f55994804778549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Yoshida?= Date: Wed, 6 Dec 2023 20:56:04 -0300 Subject: [PATCH] =?UTF-8?q?[FIX]:=20erro=20de=20renderiza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/CreateTrilhas/index.js | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/frontend/src/pages/CreateTrilhas/index.js b/frontend/src/pages/CreateTrilhas/index.js index a58418ed..807746f1 100644 --- a/frontend/src/pages/CreateTrilhas/index.js +++ b/frontend/src/pages/CreateTrilhas/index.js @@ -1,4 +1,4 @@ -import {React, useState} from "react"; +import React, {useState, useEffect} from "react"; import { useFormik } from "formik"; import { useNavigate } from "react-router-dom"; import { ChakraProvider } from "@chakra-ui/react"; @@ -42,7 +42,7 @@ const CreateTrilhas = () => { nomeTrilha: "", descricao: "", serie: "", - eletivas: [], + eletivas: "", }, validationSchema: yup.object({ nomeTrilha: yup @@ -107,18 +107,20 @@ const CreateTrilhas = () => { }, }); - const fetchEletivas = async () => { - try { - const response = await axios.get('http://localhost:3001/elective/electives'); - setEletivas(response.data); - } catch (error) { - console.error('Erro ao buscar eletivas:', error); - } finally { - setIsLoading(false); - } - }; + useEffect(() => { + const fetchEletivas = async () => { + try { + const response = await axios.get('http://localhost:3001/elective/electives'); + setEletivas(response.data); + } catch (error) { + console.error('Erro ao buscar eletivas:', error); + } finally { + setIsLoading(false); + } + }; - fetchEletivas(); + fetchEletivas(); // Chama a função apenas uma vez durante a montagem do componente + }, []); return ( @@ -211,7 +213,7 @@ const CreateTrilhas = () => { ): ( eletivas.map((eletiva) => ( - + {eletiva.name} ))