亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 React-Particles-JS 庫導入此接口?

如何從 React-Particles-JS 庫導入此接口?

慕斯709654 2023-10-17 16:56:02
我正在嘗試將我的參數與react-articles-js 庫中的JSX 分開。我將參數放在一個對象中:let options = {        "particles": {            "number": {                "value": 50            },            "size": {                "value": 3            }        },        "interactivity": {            "events": {                "onhover": {                    "enable": true,                    "mode": "repulse"                }            }        }    }然后我寫我的 JSX:<Particles params={options}/>當我這樣做時,我收到錯誤The types of 'interactivity.events.onhover.mode' are incompatible between these types.    Type 'string' is not assignable to type '"repulse" | "grab" | "push" | "remove" | "bubble" | InteractivityMode[] | undefined'.  TS2322我無法導入 InteractivityMode 接口,因為它未在庫中導出。我不知道在這里做什么。
查看完整描述

1 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

如果你檢查它的類型定義

https://github.com/Wufe/react-particles-js/blob/master/index.d.ts

export type IParticlesParams = RecursivePartial<{

  ...

}>


export interface ParticlesProps {

    width?: string;

    height?: string;

    params?: IParticlesParams;

    style?: any;

    className?: string;

    canvasClassName?: string;

}


type Particles = ComponentClass<ParticlesProps>;

因此導入類型IParticlesParams并使用它


import { Particles, IParticlesParams } from "react-particles-js";


let options: IParticlesParams = {

  ...

}

如果有任何進一步的類型錯誤,請像平常一樣在文件中處理它就可以了


查看完整回答
反對 回復 2023-10-17
  • 1 回答
  • 0 關注
  • 107 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號