본문 바로가기
안녕 버그친구들

리액트 Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

by 정ㅇr 2021. 11. 15.
728x90
// render() 부분 코드 일부
const inventoryListBySO = () => {
            let result = [];
            let numberForKey = 0;
            pricePolicyStore.selectedInventoryList.length > 0 &&
			// ... 생략
};
// return() 부분 코드 일부
// 처음에 inventoryListBySO 라고만 선언함
<GridItem xs={12} sm={10}>
    <ol>
        {inventoryListBySO()}
    </ol>
</GridItem>

render() 부분에 함수를 선언하고, return 부분에서 이 함수를 실행을 안해줘서 생긴 버그다.

함수로 선언했으니까 당연히 실행을 해줘야 코드가 돌아가는데, 함수명만 선언해줘서 코드가 작동을 안했다.

 

 

참고한 사이트

https://kyounghwan01.github.io/blog/dev-report/2020/20_08/#_8%E1%84%8B%E1%85%AF%E1%86%AF-%E1%84%8B%E1%85%B5%E1%84%89%E1%85%B2-%E1%84%8B%E1%85%AD%E1%84%8B%E1%85%A3%E1%86%A8

반응형

댓글