第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

轉(zhuǎn)發(fā) ref 到 react.FC 給出類型錯(cuò)誤:屬性 ref 不存在于類型

轉(zhuǎn)發(fā) ref 到 react.FC 給出類型錯(cuò)誤:屬性 ref 不存在于類型

胡子哥哥 2023-03-10 15:06:30
我在這里學(xué)習(xí)如何使用前向引用我有一個(gè) FC,我需要在其中初始化所有引用,然后將它們傳遞給它的子項(xiàng),這樣我就可以獲得一些 chartjs 圖表的畫布實(shí)例。但是使用 forwardRef 我得到一個(gè)類型錯(cuò)誤,說 ref 不是孩子的屬性。const BUIDashboard: React.FC = () => {    const chartRef = React.createRef<RefObject<HorizontalBar>>()...    return (      <Child           ref={chartRef} <------------------- TYPE ERROR HERE          isLoading={isLoadingChild}          data={childData} />     )}child沒有錯(cuò)誤但是是這樣設(shè)置的type Props = {  rootProps?: DashboardCardProps  isLoading?: boolean  data?: BUIMetrics['breachBreakdownByOutcome']}const Child: React.FC<Props> = React.forwardRef(({ rootProps, isLoading, data }, ref: RefObject<HorizontalBar>) => {    return (      <HorizontalBar ref={ref}/>    )}我是否錯(cuò)誤地為孩子定義了參數(shù)?我認(rèn)為問題可能出在這一行const Child: React.FC<Props>所以我將道具類型更新為type Props = {  rootProps?: DashboardCardProps  isLoading?: boolean  data?: BUIMetrics['breachBreakdownByOutcome']} & { ref: RefObject<HorizontalBar> }但是,子組件聲明會(huì)拋出此錯(cuò)誤:TS2322: Type 'ForwardRefExoticComponent<Pick<Props, "rootProps" | "isLoading" | "data"> & RefAttributes<HorizontalBar>>' is not assignable to type 'FC<Props>'.  Types of property 'defaultProps' are incompatible.    Type 'Partial<Pick<Props, "rootProps" | "isLoading" | "data"> & RefAttributes<HorizontalBar>> | undefined' is not assignable to type 'Partial<Props> | undefined'.      Type 'Partial<Pick<Props, "rootProps" | "isLoading" | "data"> & RefAttributes<HorizontalBar>>' is not assignable to type 'Partial<Props>'.        Types of property 'ref' are incompatible.          Type '((instance: HorizontalBar | null) => void) | RefObject<HorizontalBar> | null | undefined' is not assignable to type 'RefObject<HorizontalBar> | undefined'.            Type 'null' is not assignable to type 'RefObject<HorizontalBar> | undefined'.這也是明目張膽的廣告,但我正試圖解決這個(gè)問題以解決下面鏈接的另一個(gè)問題。如果您對這個(gè)問題有任何見解,也請告訴我。謝謝。 
查看完整描述

1 回答

?
天涯盡頭無女友

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊

type Props = {

  rootProps?: DashboardCardProps

  isLoading?: boolean

  data?: BUIMetrics['breachBreakdownByOutcome']

}


const Child = React.forwardRef<RefObject<HorizontalBar>,Props>(({ rootProps, isLoading, data, children }, ref) => {

    return (

      <HorizontalBar ref={ref}/>

    );

})


查看完整回答
反對 回復(fù) 2023-03-10
  • 1 回答
  • 0 關(guān)注
  • 253 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)