Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 15 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import React from 'react';
import React, { useState , useEffect} from 'react';
import axios from 'axios';
import Section from './Section';
import Arama from './Arama';

const App = () => {
// Try to think through what state you'll need for this app before starting. Then build out
Expand All @@ -7,10 +10,48 @@ const App = () => {
// 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.
const [data, setData] = useState([]);
const [arama, setArama] = useState("");
const [icerik, setİcerik] = useState("");

useEffect(() => {
axios.get('https://swapi.dev/api/people/')
.then((response) => {
setData(response.data);
})
.catch(function (error) {
console.log(error);
})
},[]);
function handleClick(name) {
setİcerik(name=== icerik ? null : name);
}

return (
<div className="App">
<h1 className="Header">Karakterler</h1>
<h1 className="Header">Star Wars Karakter Listesi</h1>
{<Arama setArama={setArama} arama={arama}/>}
{data
.filter((person) => {
if(arama === "") {
return person;
}
else if (
person.name.toLowerCase().includes(arama.toLocaleLowerCase())
){
return person;
}
})
.map((person) => {
return (
<Section
key={person.name}
data={person}
handleClick={handleClick}
icerik={icerik}
setİcerik={setİcerik}/>
);
})}
</div>
);
}
Expand Down