frontend/React

[오류] Type '{ children: Element[]; }' has no properties in common with type 'IntrinsicAttributes'.

머스타드코드 2022. 9. 4. 18:15

문제의 코드, children에 계속 밑줄이 그어짐

const TodosContextProvider: React.FC<Props> = (props) => {
  return (
  <TodosContext.Provider value={contextValue}>
    {props.children}
  </TodosContext.Provider>
  )
}

해결

type Props = {
  children?: React.ReactNode;
};

 

children 정의. react 18 에선 children지원하지 않는다고 함.

 

리액트 18의 타입스크립트 타입 변경점

React(리액트) 18이 얼마 전에 출시했습니다. 개발하시는 프로젝트에 이미 업데이트 했거나 조만간 업데이트 하실 계획일텐데요. 리액트와 Typescript(타입스크립트)를 같이 사용했던 프로젝트라면

blog.shiren.dev