source: reactapp/src/Pages/Professor.js@ 3a44163

main
Last change on this file since 3a44163 was 3a44163, checked in by unknown <mlviktor23@…>, 2 years ago

created OpinionTree component

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[7cb8c3c]1import React, { useEffect, useState } from "react";
[3a44163]2import { Outlet, useParams } from "react-router-dom";
3import OpinionTree from "../Components/OpinionTree";
[7cb8c3c]4
[3a44163]5function Professor(props) {
[7cb8c3c]6 let params = useParams();
7
[4a64cf0]8 let [professor, setProfessor] = useState(null);
9 let [loaded, setLoaded] = useState(null);
[7cb8c3c]10
11 useEffect(() => {
[4a64cf0]12 const url = `http://192.168.0.17:8080/public/professor/${params.professorId}`;
[7cb8c3c]13
14 const fetchData = async () => {
15 try {
16 const response = await fetch(url);
17 const json = await response.json();
18 setProfessor(json);
[4a64cf0]19 setLoaded(true);
[7cb8c3c]20 } catch (error) {
[3a44163]21 console.log("Error", error);
[7cb8c3c]22 }
23 };
24
25 fetchData();
26 }, []);
27
[4a64cf0]28 if (loaded) {
29 return (
[7cb8c3c]30 <div>
[3a44163]31 <h2>{professor.professorName}</h2>
32 <h3>{professor.faculty.facultyName}</h3>
33 <h3>Мислења</h3>
34 <div className="opinionTree">
35 <OpinionTree professor={professor} />
36 </div>
[4a64cf0]37 <Outlet />
[7cb8c3c]38 </div>
[4a64cf0]39 );
40 } else {
41 return (
42 <div>
43 <p>loading</p>
44 <Outlet />
45 </div>
46 );
47 }
[7cb8c3c]48}
49
50export default Professor;
Note: See TracBrowser for help on using the repository browser.