Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import './App.css';
import axios from 'axios';
import styled from 'styled-components';

import Characters from './components/Characters';

const StyledDiv = styled.div`
display: flex;
justify-content: center;
align-items: center;
`

const App = () => {
// Try to think through what state you'll need for this app before starting. Then build out
// the state properties here.

const [characters, setCharacters] = useState([]);

// Fetch characters from the API in an effect hook. Remember, anytime you have a
// side effect in a component, you want to think about which state and/or props it should
// sync up with, if any.

useEffect(() => {
axios.get('https://swapi.dev/api/people')
.then(response => {
console.log(response);
setCharacters(response.data);
})
.catch(error => {
console.log(error);
})
}, [])

return (
<div className="App">
<h1 className="Header">Characters</h1>
<StyledDiv>
<Characters characters={characters} />
</StyledDiv>
</div>
);
}
Expand Down