codestates / codestates/Memory-It
[Error Handling] 컴포넌트속 컴포넌트안에서 redux useSelector로 state 불러올때 발생하는 오류
- Dominant language
- JavaScript
- Stars
- 1
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
### 어떤 에러인가요?
+ 컴포넌트속 컴포넌트안에서 redux useSelector로 state 불러올때 발생하는 오류
### 에러 메시지
```
Uncaught (in promise) Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at Object.throwInvalidHookError (react-dom.development.js:14906)
at useContext (react.development.js:1504)
at useReduxContext (useReduxContext.js:21)
at useSelector (useSelector.js:125)
at GetPost (DiaryType.js:145)
at onClick (DiaryType.js:168)
```
### 에러 핸들링 방법
+ 컴포넌트속 컴포넌트안에서 redux useSelector로 state 불러올때 발생하는 오류
+ 오류 코드를 보고 컴포넌트속 컴포넌트에서 redux useSelector로 state 불러오는걸 상위 컴포넌트로 이동 시켰다.
+ 훅은 오직 기능 컴포넌트 바디안에서만 불러올 수 있다.
+ 참고 onClick 사용시 여러 컴포넌트나 디스패치불러오고 싶으면 onClick={()=>{디스패치1 디스패치2 컴포넌트()}} 형태로 불러올 수 있다.
```jsx
// 코드가 들어가도 좋아요!
``` {
dispatch(changeImage(post))
dispatch(detailedPostMode())
dispatch(changePostId(post.id))
GetPost()
}}/>
### 에러 핸들링을 위해 참고한 레퍼런스 링크
[레퍼런스 링크](이곳에 url을 입력해주세요)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.