-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4주차] 정희수 미션 제출합니다. #16
base: master
Are you sure you want to change the base?
Changes from 1 commit
2a67610
6ff33a8
4eab43e
1346d7f
29ae0d6
37ff39a
af988cc
cd654cc
ae76f1e
8550abb
f47fa43
8a9c3c1
c6a0e37
16d783d
338d626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,31 @@ import {useRecoilState,useRecoilValue,} from 'recoil'; | |
import { userState } from '../../recoil/atom'; | ||
import Header from '../../components/Header'; | ||
import FriendItem from './FriendItem'; | ||
import Search from './Search'; | ||
import styled from "styled-components" | ||
|
||
const Friends = () => { | ||
const [user, setUser] = useRecoilState<Object[]>(userState); | ||
const [search, setSearch] = useState(0); | ||
|
||
const onClick = () => { | ||
if(search === 0){ | ||
setSearch(1); | ||
}else{ | ||
setSearch(0); | ||
} | ||
} | ||
|
||
return ( | ||
<StyledBlock> | ||
<Header/> | ||
<StyledContent> | ||
친구 | ||
<StyledButton onClick={onClick}>🔍</StyledButton> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이렇게 해주면 onClick 함수를 따로 작성하지 않고 구현할 수 있을 것 같습니다.! |
||
{ | ||
search === 0 ? | ||
<Search/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 주절주절 한파일에 다 작성했는데 .. Search 컴포넌트를 따로 작성하셨군요.! 저도 이렇게 해야겠습니다..ㅎㅎ 👍 |
||
: | ||
user.map((u)=>( | ||
<FriendItem | ||
key={Object.values(u)[0]} | ||
|
@@ -29,6 +43,14 @@ const Friends = () => { | |
); | ||
}; | ||
|
||
const StyledButton = styled.button` | ||
float: right; | ||
border: none; | ||
outline:none; | ||
background: white; | ||
font-size: medium; | ||
` | ||
|
||
const StyledBlock = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, {useState, useEffect} from 'react'; | ||
import {useRecoilState,useRecoilValue,} from 'recoil'; | ||
import { userState } from '../../recoil/atom'; | ||
import FriendItem from './FriendItem'; | ||
import styled from "styled-components" | ||
|
||
const Search = () => { | ||
const [user, setUser] = useRecoilState<Object[]>(userState); | ||
|
||
const [search, setSearch] = useState(""); | ||
const onChange = (e:React.ChangeEvent<HTMLInputElement>) => { | ||
setSearch(e.target.value); | ||
} | ||
|
||
const filterUser= user.filter((p) => { | ||
let result = Object.values(p)[1].replace(" ","").toLocaleLowerCase().includes(search.toLocaleLowerCase()); | ||
console.log(Object.values(p)[1],result); | ||
return result; | ||
}) | ||
|
||
return ( | ||
<div> | ||
<br/> | ||
<StyledInput type="text" value={search} onChange={onChange}/> | ||
{ | ||
filterUser.map((u)=>( | ||
<FriendItem | ||
key={Object.values(u)[0]} | ||
id={Object.values(u)[0]} | ||
name={Object.values(u)[1]} | ||
src={Object.values(u)[2]} | ||
number={Object.values(user).length} | ||
/> | ||
)) | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
const StyledInput = styled.input` | ||
width: 250px; | ||
height: 20px; | ||
` | ||
|
||
export default Search; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오옷 친구 수도 추가하셨네용..!!