-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: vaniilaJS -> React #23
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
Conversation
chaerin-dev
commented
Jun 10, 2022
- 상태관리 없이 구현하는 것이 더 어려워서 Recoil을 이용한 전역상태관리까지 같이 구현하게 되었습니다.
- React 공부를 따로 할 시간이 없어 지난 미팅 때 @codeisneverodd 님께서 설명해주신 내용과 구글링만을 바탕으로 구현하다보니 부족한 점이 많습니다. 리뷰 부탁드립니다.
- CSS의 경우 Styled Component로 다시 구현하신다고 하셔서 아예 import 하지 않았습니다.
- @yongchanson CSS 적용하실 때 로딩컴포넌트 position을 absolute로 해서 나머지 컴포넌트들을 덮도록 해주시면 될 것 같습니다.
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.
좋은 코드 잘 보았습니다! 고생 많이셨을 것 같네요 👍
리뷰 남겼으니 답글을 남기셔도 좋고, 반영을하셔도 좋을 것 같습니다!!
export const solutionState = atom({ | ||
key: "solutionState", | ||
default: { | ||
level: 1, | ||
fileName: "", | ||
solution: [], | ||
}, | ||
}); | ||
|
||
const root = ReactDOM.createRoot(document.getElementById('root')); | ||
export const solutionNoState = atom({ | ||
key: "solutionNoState", | ||
default: 0, | ||
}); | ||
|
||
export const loadingState = atom({ | ||
key: "loadingState", | ||
default: true, | ||
}); |
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.
atom.js 라는 파일을 새롭게 만들어 관리하면 좋을 것 같네요!
).join('')} | ||
`; | ||
export default function SearchableList() { | ||
let [fileListHTML, changeState] = useState(""); |
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.
상태는 직접 변동이 불가능하고 set함수로만 변경할 수 있기 때문에 const
로 선언하는 것이 좋아보입니다! 그리고 state가 여러개가되면 이름의 혼동이 있을 수 있기 때문에 다음과 같이 수정하는 것이 좋아보입니다.
const [fileListHTML, setFileListHTML] = useState("")
const setLoadingState = useSetRecoilState(loadingState); | ||
|
||
// TODO: ``부분 수정 필요.. | ||
(async function fillList() { |
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.
fillList에 대한 로직이 개선되어야할 것으로 보입니다! 우선 기존 로직을 이용해서 잘 구현해주셨다고 생각합니다. 하지만 상태 값이 생겼기 때문에 이제는 직접 돔을 채워주는 것이 아닌, 상태값을 이용한 형태로 구현이 가능할 것 같습니다.
예시를 적어보자면 아래와 같습니다.
const POSSIBLE_LEVELS = [1, 2, 3, 4, 5];
const [fileList, setFileList] = useState({})
useEffect(()=>{
const newFileList = Object.assign({},fileList)
for (const level of POSSIBLE_LEVELS) {
newFileList[level] = await getFileList(level);
}
setFileList(newFileList)
},[ ])
// 돔 내부
{Object.entries(fileList).map(([level, files])=>{
//로직 작성
})}
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.
GitHub을 통해 작성한 것이라 오류가 있을 수 있습니다! 참고용으로만 보아주세요 ㅎㅎ
@codeisneverodd 👍👍👍 리뷰 남겨주신 부분 반영해보도록 하겠습니다! |