From 221fdf516eef3c066605e6d0abef64a9e0026549 Mon Sep 17 00:00:00 2001 From: Cassius-Cassity <80988165+Cassius-Cassity@users.noreply.github.com> Date: Fri, 8 Oct 2021 17:49:58 -0600 Subject: [PATCH] Really want to go back over this stuff --- src/App.js | 33 ++++++++++++++++++++++++++++++--- src/components/Character.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index 5e69e9fdd..597592bc9 100644 --- a/src/App.js +++ b/src/App.js @@ -1,18 +1,45 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import './App.css'; +import axios from 'axios'; +import Character from './components/Character' + + 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([]) + //const [currentCharacterId, setCurrentCharacterId] =useState(null) + // const [CharactersId, setCharactersId] = useState(null) // 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/?format=api') + .then(res=> { + setCharacters(res.data) + + }).catch(err=>{ + console.log(err) + }) + },[]) + + + + return (

Characters

-
+ { + Characters.map(character =>{ + return + }) + } + + + ); } diff --git a/src/components/Character.js b/src/components/Character.js index 4083249c0..32dbb37e8 100644 --- a/src/components/Character.js +++ b/src/components/Character.js @@ -1 +1,32 @@ // Write your Character component here +import React, {useState, useEffect } from 'react' +import axios from 'axios' + +export default function Character(props) { + const {characterId} = props + const [details, setDetails] = useState(null) + + useEffect(()=> { + axios.get('https://swapi.dev/api/people/?format=api') + .then(res=> { + setDetails(res.data) + + }).catch(err=>{ + console.log(err) + }) + },[characterId]) + + const newDetails = details.map(det =>{ + return det + }) + + return ( +
+
  • Birth Year {newDetails.birth_year}
  • +
  • Films {newDetails.films}
  • +
  • gender {newDetails.gender}
  • +
  • Starships {newDetails.starships}
  • +
    + ) + +} \ No newline at end of file