[英]How to “import” a 3rd party javascript module to my react project?
我正在嘗試調整這個名為react-add-to-calendar 的模塊,以在單擊下拉項目時支持onClick
事件,因為該庫的創建者似乎不再維護它。 我已將ReactAddToCalendar.js
文件移到我的項目中,並像這樣要求它:
import AddToCalendar from 'apps/bookings/components/ReactAddToCalendar'
根據這個答案,還有一個看起來像這樣的ReactAddToCalendar.d.ts
:
declare module "ReactAddToCalendar";
但現在我收到了這個錯誤:
File '.../{project_name}/app/javascript/apps/bookings/components/ReactAddToCalendar.d.ts' is not a module.
我試過到處尋找如何克服這個問題,但我找不到任何東西。
您必須從命令行像這樣安裝它:
npm install react-add-to-calendar --save
然后您只需將其放入所需的組件中:
import AddToCalendar from 'react-add-to-calendar';
來自組件的 git 的示例:
import React from 'react';
import AddToCalendar from 'react-add-to-calendar';
class Example extends React.Component {
static displayName = 'Example';
state = {
event: {
title: 'Sample Event',
description: 'This is the sample event provided as an example only',
location: 'Portland, OR',
startTime: '2016-09-16T20:15:00-04:00',
endTime: '2016-09-16T21:45:00-04:00'
}
};
render() {
return <AddToCalendar event={this.state.event}/>;
};
}
說明就在那里。 或者你不能從 NPM 安裝模塊?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.