Commit b6b1b067 authored by zarina's avatar zarina 🌊

#3, Добавлен вывод всех цитат на главную страницу

parent 55815c3a
import React from 'react';
import { Card, Button, CardHeader, CardFooter, CardBody,
CardTitle, CardText } from 'reactstrap';
const Quote = props => {
return (
<div>
<Card>
<CardBody>
<CardTitle>{props.author}</CardTitle>
<CardText>{props.text}</CardText>
<Button color='danger'>Delete</Button>
<Button color='info'>Edit</Button>
</CardBody>
<CardFooter className='text-hide'>{props.category}</CardFooter>
</Card>
</div>
);
};
export default Quote;
\ No newline at end of file
......@@ -3,6 +3,7 @@ import {Switch, Route} from "react-router-dom";
import {Container} from "reactstrap";
import './App.css';
import QuoteForm from "./QuoteForm/QuoteForm";
import Quotes from "./Quotes/Quotes";
function App() {
return (
......@@ -10,6 +11,8 @@ function App() {
<Container>
<Switch>
<Route path="/add-quote" exact component={QuoteForm}/>
<Route path="/" exact component={Quotes}/>
</Switch>
</Container>
</>
......
import React, {useEffect, useState} from "react";
import axios from '../../axios-quote'
import Quote from "../../components/Quote/Quote";
const Quotes = () => {
const [quotes, setQuotes] = useState({});
useEffect(() => {
axios.get('/quotes.json').then(
response => {
setQuotes(response.data)
}
)
}, []);
const printQuotes = () => {
return Object.keys(quotes).map(quote => {
return <Quote author={quotes[quote].author}
text={quotes[quote].text}
category={quotes[quote].category}
key={quote}
/>
})
};
return (
<div className='Quotes'>
{
Object.keys(quotes).length > 0 ? printQuotes() : 'Please add quotes'
}
</div>
)
};
export default Quotes
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment