【问题标题】:How to use React-Table without Node.js?如何在没有 Node.js 的情况下使用 React-Table?
【发布时间】:2021-09-07 02:03:16
【问题描述】:

我是 React 新手,我希望在没有 Node.js 的 Django 应用程序中使用 react-table。我已经在我的应用程序中嵌入了带有标准 unpkg 链接的 react-table 库,但是当我在 .js 文件中使用它的函数时,我得到了像 app.js:39 Uncaught ReferenceError: useTable is not defined 这样的错误。所有教程都导入useTableimport { useTable } from 'react-table',但是当您只是尝试在浏览器中实现这个客户端时,这是不可能的。如果没有 Node.js 及其 import 函数,我将如何使用 react-table?

【问题讨论】:

  • 这个例子使用 React 和 react-table。 codesandbox.io/s/github/tannerlinsley/react-table/tree/master/…
  • @SanishJoseph 是的,但该示例使用 Node.js 和 import 函数。我正在尝试在没有 Node.js 的情况下使用 React Table,但我不知道如何在没有 Node 的情况下访问它的任何方法。
  • 你说的是哪些功能?如果是 const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, } = useTable({ columns, data, }) 他们不是来自 Nodejs。
  • 你是想说你想使用 react-table 而不用 react 吗?
  • 不,我在我的 HTML 文件中嵌入了 React 和 React-table 作为 unpkg 脚本链接。但是,它无法识别 React-table 中的 useTable 函数。我目前认为这是因为我没有使用上面描述的import 函数。

标签: javascript reactjs react-table


【解决方案1】:

您可以使用 unpkg 将包作为脚本标签 npm。

<script src="https://unpkg.com/browse/react-table@latest/react-table.min.js" />

源反应表文档https://react-table.tanstack.com/docs/installation

【讨论】:

  • 我已经这样做了,但是我的 JS 文件无法识别 React Table 函数。他们的<script> 链接是在我加载 React Table 之后放置的,所以我相信这不是订购问题。
  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 2021-10-30
  • 2014-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-13
  • 1970-01-01
  • 2022-11-16
相关资源
最近更新 更多