[英]How to “import” a 3rd party javascript module to my react project?
I'm trying to tweak this module called react-add-to-calendar to support onClick
events when clicking the dropdown items since the creator of the library seems to be not maintaining it anymore.我正在尝试调整这个名为react-add-to-calendar 的模块,以在单击下拉项目时支持
onClick
事件,因为该库的创建者似乎不再维护它。 I've moved the ReactAddToCalendar.js
file over to my project and require it like this:我已将
ReactAddToCalendar.js
文件移到我的项目中,并像这样要求它:
import AddToCalendar from 'apps/bookings/components/ReactAddToCalendar'
And also have a ReactAddToCalendar.d.ts
that looks like this according to this answer :根据这个答案,还有一个看起来像这样的
ReactAddToCalendar.d.ts
:
declare module "ReactAddToCalendar";
But now I'm getting this error:但现在我收到了这个错误:
File '.../{project_name}/app/javascript/apps/bookings/components/ReactAddToCalendar.d.ts' is not a module.
I've tried looking everywhere on how to get over this but I can't find anything.我试过到处寻找如何克服这个问题,但我找不到任何东西。
You have to install it like this from your command line:您必须从命令行像这样安装它:
npm install react-add-to-calendar --save
and then you only have to put this in the desired component:然后您只需将其放入所需的组件中:
import AddToCalendar from 'react-add-to-calendar';
Example from the git of the component:来自组件的 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}/>;
};
}
the instructions are right over there.说明就在那里。 Or you cant install the modules from NPM?
或者你不能从 NPM 安装模块?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.