我是新来的。我想问一个最基本的问题,因为我在Google上找不到相关的文档或答案。以下是典型的react代码的前3行:
import React, { Component } from "react";
import {
Button,
Modal,
} from "reactstrap";
export default class CustomModal extends Component {
...
}
第二行导入的引导组件与react中的Component类(即react.Component)之间有什么联系?为什么CustomModal子类来自react.Component而不是reactstrap.Modal?react.Component是一种抽象类,reactstrap.Modal具体类是扩展react.Component吗?
发布于 2021-04-13 19:46:35
基本上是的。扩展React.Component以创建自己的基于自定义类的React组件。您要导入的其他组件来自库作者已经创建了组件的库。请注意,您还可以在不扩展React.Component的情况下创建基于自定义函数的function组件。我建议通过React.Component文档阅读。
关于它如何与CustomModal相关的问题,您可以使用Modal作为CustomModal中的一个组件。例如:
import React, { Component } from "react";
import {
Button,
Modal,
} from "reactstrap";
export default class CustomModal extends Component {
...
render() {
return <Modal />;
}
}
请注意,这个示例只是为了让您了解如何在您自己的自定义组件中使用导入的组件。这不一定是如何使用reactstrap.Modal
本身。
https://stackoverflow.com/questions/67080504
复制相似问题