SubNav.js 1.32 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
Kim, Subin's avatar
Kim, Subin committed
2
import { Redirect } from 'react-router-dom';
3
import { Navbar, Nav, NavDropdown } from 'react-bootstrap';
kusang96's avatar
kusang96 committed
4
5
import axios from 'axios';
import catchErrors from '../utils/catchErrors';
Kim, Subin's avatar
Kim, Subin committed
6
7

function SubNav() {
kusang96's avatar
kusang96 committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    const [categorysDiv, setCategorysDiv] = useState([])
    const [error, setError] = useState('')


    useEffect(async () => {
        try {
            const response = await axios.get('/api/categorys')
            let list = []
            Object.keys(response.data[0]).forEach((ele) => {
                const url = "/" + ele.toLowerCase()
                list.push(
                    <Nav.Link href={url}>{ele}</Nav.Link>
                )
            })
            setCategorysDiv(list)
        } catch (error) {
            catchErrors(error, setError)
        }
    }, [])
Kim, Subin's avatar
Kim, Subin committed
27
28

    return (
kusang96's avatar
kusang96 committed
29
        <Navbar sticky="top" className="flex-nowrap" style={{ top: "62px", paddingTop: "0", paddingBottom: "0", backgroundColor: "#fff" }}>
30
31
32
33
34
35
36
37
            <style type="text/css">
                {`
                .nav-link, .nav-link:hover, .nav-link:active {
                    color: #91877F;
                }
                `}
            </style>
            <Nav>
kusang96's avatar
kusang96 committed
38
                {categorysDiv.map(item => item)}
39
40
            </Nav>
        </Navbar>
Kim, Subin's avatar
Kim, Subin committed
41
42
43
44
    )
}

export default SubNav